楼主: jpld
22590 6

[学习分享] 画图神器ggplot2之一:geom_point [推广有奖]

  • 2关注
  • 50粉丝

已卖:4份资源

讲师

2%

还不是VIP/贵宾

-

威望
0
论坛币
1264 个
通用积分
9.5333
学术水平
120 点
热心指数
120 点
信用等级
99 点
经验
1249 点
帖子
192
精华
0
在线时间
271 小时
注册时间
2009-5-29
最后登录
2024-6-25

楼主
jpld 发表于 2015-10-10 21:34:50 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币

p <- ggplot(mtcars, aes(wt, mpg))

p + geom_point()

1.png

# Add aesthetic mappings

p + geom_point(aes(colour = qsec))

2.png

p + geom_point(aes(alpha = qsec))

3.png

p + geom_point(aes(colour = factor(cyl)))

4.png

p + geom_point(aes(shape = factor(cyl)))

5.png

p + geom_point(aes(size = qsec))

6.png

# Change scales

p + geom_point(aes(colour = cyl)) + scale_colour_gradient(low ="blue")

7.png

p + geom_point(aes(size = qsec)) + scale_area()

scale_area is deprecated. Usescale_size_area instead.

Note that the behavior of scale_size_area is slightly different:

  bydefault it makes the area proportional to the numeric value. (Deprecated; lastused in version 0.9.2)

8.png

p + geom_point(aes(shape = factor(cyl))) + scale_shape(solid = FALSE)

9.png

# Set aesthetics to fixed value

p + geom_point(colour = "red", size = 3)

10.png

qplot(wt, mpg, data = mtcars, colour = I("red"), size = I(3))

11.png

# Varying alpha is useful for large datasets

d <- ggplot(diamonds, aes(carat, price))

d + geom_point(alpha = 1/10)

12.png

d + geom_point(alpha = 1/20)

13.png

d + geom_point(alpha = 1/100)

14.png

# You can create interesting shapes by layering multiple points of

# different sizes

p <- ggplot(mtcars, aes(mpg, wt))

p + geom_point(colour="grey50", size = 4) +geom_point(aes(colour = cyl))

15.png

p + aes(shape = factor(cyl)) +

  geom_point(aes(colour =factor(cyl)), size = 4) +

geom_point(colour="grey90", size = 1.5)

16.png

p + geom_point(colour="black", size = 4.5) +

geom_point(colour="pink", size = 4) +

  geom_point(aes(shape =factor(cyl)))

17.png

# These extra layers don't usually appear in the legend, but we can

# force their inclusion

p + geom_point(colour="black", size = 4.5, show_guide = TRUE) +

geom_point(colour="pink", size = 4, show_guide = TRUE) +

  geom_point(aes(shape =factor(cyl)))

18.png

# Transparent points:

qplot(mpg, wt, data = mtcars, size = I(5), alpha = I(0.2))

19.png

# geom_point warns when missing values have been dropped from the data set

# and not plotted, you can turn this off by setting na.rm = TRUE

mtcars2 <- transform(mtcars, mpg = ifelse(runif(32) < 0.2, NA, mpg))

qplot(wt, mpg, data = mtcars2)

Warning message:

Removed 11 rows containing missing values(geom_point).

20.png

qplot(wt, mpg, data = mtcars2, na.rm = TRUE)

21.png

# Use qplot instead

qplot(wt, mpg, data = mtcars)

22.png

qplot(wt, mpg, data = mtcars, colour = factor(cyl))

23.png

qplot(wt, mpg, data = mtcars, colour = I("red"))

24.png


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:ggplot2 gplot Point plot EOM

沙发
npucass 发表于 2015-10-10 21:41:59 来自手机
jpld 发表于 2015-10-10 21:34
p
3ks

藤椅
cheetahfly 在职认证  发表于 2015-10-12 09:29:12
好帖子!

板凳
RecaidoJ 发表于 2016-11-22 15:01:31
想问楼主,怎么更改图例的大小,插入到word里图例几乎看不见了

报纸
远行半夏 发表于 2017-9-12 17:04:12
谢谢楼主

地板
屋檐滴语 发表于 2017-9-12 17:12:43
R graphics cookbook学完绝对收益非浅。

7
远行半夏 发表于 2017-9-12 18:54:28
RecaidoJ 发表于 2016-11-22 15:01
想问楼主,怎么更改图例的大小,插入到word里图例几乎看不见了
theme(legend.title=element_text(size=20))修改size后的值

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-26 10:58