逐条输入构建图形元素

颜色

参数描述
col默认绘图颜色
fg图形前景颜色
bg图形背景颜色
col.axis坐标轴刻度文字颜色
col.lab坐标轴标签颜色
col.main标题颜色
col.sub副标题颜色
plot(women,main="身高VS体重散点图",sub="数据来源:women数据集",col="red",col.main="green",col.sub="blue",col.axis="grey",col.lab="yellow")

在这里插入图片描述

主题函数描述
colors()657种颜色
rainbow()彩虹色
heat.colors()红渐变黄再到白
terrain.colors()绿渐变黄,到棕,到白
topo.colors()蓝到青到黄到棕
cm.colors()青到白到粉红
par(mfrow=c(3,3))
barplot(rep(1,7),col = rainbow(7),main = "rainbow")
barplot(rep(1,7),col = heat.colors(7),main = "heat.colors")
barplot(rep(1,7),col = terrain.colors(7),main = "terrain.colors")
barplot(rep(1,7),col = topo.colors(7),main = "topo.colors")
barplot(rep(1,7),col = cm.colors(7),main = "cm.colors")
par(mfrow=c(1,1))

在这里插入图片描述
文字

plot(0:4,type = "n",axes = F,xlab = NA,ylab = NA)
type <- c("正常字体","粗体","斜体","粗斜体")
for (i in 1:4) {
  text(2,5-i,labels =paste0("font=",i,":",type[i]),font = i )
}

在这里插入图片描述
type
what type of plot should be drawn. Possible types are
“p” for points,
“l” for lines,
“b” for both,
“c” for the lines part alone of “b”,
“o” for both ‘overplotted’,
“h” for ‘histogram’ like (or ‘high-density’) vertical lines,
“s” for stair steps,
“S” for other steps, see ‘Details’ below,
“n” for no plotting.

plot(0:5,type = "n",axes = F,xlab = NA,ylab = NA)
text(2,5,labels = "cex=0.5:0.5倍",cex=0.5)
text(2,4,labels = "cex=0.8:0.8倍",cex=0.8)
text(2,3,labels = "cex=1:正常大小",cex=1)
text(2,2,labels = "cex=1.5:1.5倍",cex=1.5)
text(2,1,labels = "cex=2:2倍",cex=2)

在这里插入图片描述
点元素

plot(1,col="white",xlim = c(1,7),ylim = c(1,5),
     main = "pch=",xlab = NA,ylab = NA)
for ( i in c(0:25) ){
  x<- (i %/% 5)*1 + 1   #取商,保证x轴不变
  y <- 6-(i%%5)-1       #取模,y值变化
  if(length(which(c(21:25)==i)>=1)){
    points(x,y,pch=i,col="blue",bg="yellow",cex=2)
  }else{
    points(x,y,pch=i,cex=2)
  }
  text(x+0.2,y,labels = i)
}

在这里插入图片描述

points(6,4,pch="*",cex=2)
points(6,3,pch="?",cex=2)
points(6,2,pch="a",cex=2)
points(6,1,pch="A",cex=2)
points(7,5,pch="0",cex=2)
points(7,4,pch=".",cex=2)
points(7,3,pch="+",cex=2)
points(7,2,pch="-",cex=2)
points(7,1,pch="|",cex=2)

在这里插入图片描述
线元素

数值线型
0不划线
1实线
2虚线
3点线
4点虚
5长虚
6双虚
plot(x=1:10,y=rep(1,10),type = "l",lty=0,ylim = c(1,8),xlim = c(-1,10),
     axes = F,xlab = NA,ylab = NA)
text(0,1,labels = "lty=0")
for (i in 2:7) {
  lines(x=1:10,y=rep(i,10),lty=i-1,xlab=NA,ylab=NA)
  text(0,i,labels = paste0("lty=",i-1))
}

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值