颜色
参数 | 描述 |
---|---|
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))
}