温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

怎么用ggplot2的geom_point绘制散点图

发布时间:2022-03-18 17:26:33 来源:亿速云 阅读:578 作者:iii 栏目:开发技术

本篇内容介绍了“怎么用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绘制散点图”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI