R基础绘图学习笔记(一)

了解绘图

1.散点图

yaxs=r

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.画线图

01
02
代码实现:

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.条形图

1
2
3
4
代码如下:

#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)

直方图和密度图

1
2
3
代码如下:

    hist(rnorm(1000))
    hist(islands)
    plot(density(rnorm(1000)))

箱线图

1
2
代码如下

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")

热图,地图

1
2
3
代码如下:

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

1
2

pairs(iris[,1:4])

plot(iris[,1:4],
main="Relationships between characteristics of iris flowers",
pch=19,
col="blue",
cex=0.9)
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值