怎么用ggplot2的geom_point绘制散点图
本篇内容介绍了“怎么用ggplot2的geom_point绘制散点图”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
ggplot2可以利用geom_point绘制散点图,而点的形状控制参数shape会显示多少效果呢?(注意此处只介绍shape的设定,不是aes(shape)映射)

可以通过查询?shape
获得以下内容:
#Shapeexamples#Shapetakesfourtypesofvalues:anintegerin[0,25],#asinglecharacter--whichusesthatcharacterastheplottingsymbol,#a.todrawthesmallestrectanglethatisvisible(i.e.,aboutonepixel)#anNAtodrawnothingp+geom_point()p+geom_point(shape=5)p+geom_point(shape="k",size=3)p+geom_point(shape=".")p+geom_point(shape=NA)
1、[0,25]之间的数值表示不同的形状
利用下数据固定X,Y,shape
datXYshape11602261336244635564615572568357945810559111410122411133412144413155414161315172316183317194318205319211220222221233222244223255224261125
代码中确定X ,Y,在shape中设定下形状。
library(ggplot2)p=ggplot(dat,aes(x=X,y=Y))+geom_point(shape=dat$shape,size=10)print(p)
每个位置对应的形状的数字(结合数据和图片)
如果统一一个形状呢?
p=ggplot(dat,aes(x=X,y=Y))+geom_point(shape=5,size=10)print(p)
2、如果等于“k"呢?将显示"k"
p=ggplot(dat,aes(x=X,y=Y))+geom_point(shape="k",size=10)print(p)
3、如果shape是"." 将绘出有一个非常小的点(此时的size并没能调整到大小)
p=ggplot(dat,aes(x=X,y=Y))+geom_point(shape=".",size=20)print(p)
4如果shape是NA 则隐藏点
p=ggplot(dat,aes(x=X,y=Y))+geom_point(shape=NA,size=10)print(p)
“怎么用ggplot2的geom_point绘制散点图”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注恰卡编程网网站,小编将为大家输出更多高质量的实用文章!