本篇内容介绍了“怎么用ggplot2的geom_point绘制散点图”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
ggplot2可以利用geom_point绘制散点图,而点的形状控制参数shape会显示多少效果呢?(注意此处只介绍shape的设定,不是aes(shape)映射)
可以通过查询?shape
获得以下内容:
# Shape examples
# Shape takes four types of values: an integer in [0, 25],
# a single character-- which uses that character as the plotting symbol,
# a . to draw the smallest rectangle that is visible (i.e., about one pixel)
# an NA to draw nothing
p + 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
dat
X Y shape
1 1 6 0
2 2 6 1
3 3 6 2
4 4 6 3
5 5 6 4
6 1 5 5
7 2 5 6
8 3 5 7
9 4 5 8
10 5 5 9
11 1 4 10
12 2 4 11
13 3 4 12
14 4 4 13
15 5 4 14
16 1 3 15
17 2 3 16
18 3 3 17
19 4 3 18
20 5 3 19
21 1 2 20
22 2 2 21
23 3 2 22
24 4 2 23
25 5 2 24
26 1 1 25
代码中确定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绘制散点图”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注天达云网站,小编将为大家输出更多高质量的实用文章!