前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >画图神器ggplot2之一:geom_point

画图神器ggplot2之一:geom_point

作者头像
统计学家
发布2019-04-10 10:23:03
2.6K0
发布2019-04-10 10:23:03
举报

Examples

代码语言:javascript
复制
p <- ggplot(mtcars, aes(wt, mpg))
p + geom_point()
# Add aesthetic mappings
p + geom_point(aes(colour = qsec))
p + geom_point(aes(alpha = qsec))
p + geom_point(aes(colour = factor(cyl)))
p + geom_point(aes(shape = factor(cyl)))
p + geom_point(aes(size = qsec))
# Change scales
p + geom_point(aes(colour = cyl)) + scale_colour_gradient(low = "blue")
p + geom_point(aes(size = qsec)) + scale_area()scale_area is deprecated. Use scale_size_area instead.
  Note that the behavior of scale_size_area is slightly different:
  by default it makes the area proportional to the numeric value. (Deprecated; last used in version 0.9.2)
p + geom_point(aes(shape = factor(cyl))) + scale_shape(solid = FALSE)
# Set aesthetics to fixed value
p + geom_point(colour = "red", size = 3)
qplot(wt, mpg, data = mtcars, colour = I("red"), size = I(3))
# Varying alpha is useful for large datasets
d <- ggplot(diamonds, aes(carat, price))
d + geom_point(alpha = 1/10)
d + geom_point(alpha = 1/20)
d + geom_point(alpha = 1/100)
# 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))
p + aes(shape = factor(cyl)) +
  geom_point(aes(colour = factor(cyl)), size = 4) +
  geom_point(colour="grey90", size = 1.5)
p + geom_point(colour="black", size = 4.5) +
  geom_point(colour="pink", size = 4) +
  geom_point(aes(shape = factor(cyl)))
# 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)))
# Transparent points:
qplot(mpg, wt, data = mtcars, size = I(5), alpha = I(0.2))
# 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).
qplot(wt, mpg, data = mtcars2, na.rm = TRUE)
# Use qplot instead
qplot(wt, mpg, data = mtcars)
qplot(wt, mpg, data = mtcars, colour = factor(cyl))
qplot(wt, mpg, data = mtcars, colour = I("red"))
本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2015-10-10,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 机器学习与统计学 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Examples
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档