了解绘图
1.散点图
plot(cars$dist~cars$speed, # y~x
main="Relationship between car distance &speedr", #散点图标题
xlab="Speed (miles per hour)", #X轴标题
ylab="Distance travelled (miles)", #Y轴标题
xlim=c(0,30), #坐标轴表示范围
ylim=c(0,140),
yaxs="r", #
col="red", #设置颜色红色
pch=19) #设置符号
plot(cars$dist~cars$speed)
2.画线图
代码实现:
plot(sales$units~as.Date(sales$date,"%d/%m/%y"),
type="l", #Specify type of plot as l for line
main="Unit Sales in the month of January 2010",
xlab="Date",
ylab="Number of units sold",
col="blue")
lines(sales$units~as.Date(sales$date,"%d/%m/%y"),
col="red")
3.条形图
代码如下:
#Vertical bars
barplot(sales$ProductA,
names.arg= sales$City,
col="black")
#Horizontal bars
barplot(sales$ProductA,
names.arg= sales$City,
horiz=TRUE,
col="black")
#Grouped bars with legend
barplot(as.matrix(sales[,2:4]), beside= TRUE,
legend=sales$City,
col=heat.colors(5),
border="white")
#Horizontal grouped bars with legend
barplot(as.matrix(sales[,2:4]), beside=TRUE,
legend=sales$City,
col=heat.colors(5),
border="white",
horiz=TRUE)
直方图和密度图
代码如下:
hist(rnorm(1000))
hist(islands)
plot(density(rnorm(1000)))
箱线图
代码如下
boxplot(copper$Cu~copper$Source,
xlab="Measurement Site",
ylab="Atmospheric Concentration of Copper in ng per cubic metre",
main="Atmospheric Copper Concentrations in London")
boxplot(metals,
xlab="Metals",
ylab="Atmospheric Concentration in ng per cubic metre",
main="Atmospheric Metal Concentrations in London")
热图,地图
代码如下:
heatmap(as.matrix(mtcars),
Rowv=NA,
Colv=NA,
col = heat.colors(256),
scale="column",
margins=c(2,8),
main = "Car characteristics by Model")
image(x=1:ncol( genes),
y=1:nrow(genes),
z=t(as.matrix(genes)),
axes=FALSE,
xlab="",
ylab="" ,
main="Gene Correlation Matrix")
axis(1,at=1:ncol(genes),labels=colnames(genes),col="white",las=2,cex.axis=0.8)
axis(2,at=1:nrow(genes),labels=rownames(genes),col="white",las=1,cex.axis=0.8)
map('world', fill = TRUE,col=heat.colors(10))
emmm
pairs(iris[,1:4])
plot(iris[,1:4],
main="Relationships between characteristics of iris flowers",
pch=19,
col="blue",
cex=0.9)