如何在 R 中根据不同形状的点来绘制情节?
在基础 R 中,可以使用 plot 函数内部的 pch 参数来创建具有不同形状点的绘图。pch 值与形状的列表如下所写 -
pch = 0 display square pch = 1 display circle pch = 2 display triangle point up pch = 3 display plus pch = 4 display cross pch = 5 display diamond pch = 6 display triangle point down pch = 7 display square cross pch = 8 display star pch = 9 display diamond plus pch = 10 display circle plus pch = 11 display triangles up and down pch = 12 display square plus pch = 13 display circle cross pch = 14 display square and triangle down pch = 15 display filled square pch = 16 display filled circle pch = 17 display filled triangle point-up pch = 18 display filled diamond pch = 19 display solid circle pch = 20 display bullet (smaller circle) pch = 21 display filled circle blue pch = 22 display filled square blue pch = 23 display filled diamond blue pch = 24 display filled triangle point-up blue pch = 25 display filled triangle point down blue
示例
考虑以下矢量并创建具有三种不同形状的点图表 -
x<-sample(0:5,20,replace=TRUE) y<-sample(1:10,20,replace=TRUE) plot(x,y,pch=c(16,17,18))
输出
创建具有不同形状颜色的相同绘图 -
示例
plot(x,y,pch=c(16,17,18),col=c("red","yellow","blue"))
输出
广告