ggplot2之Layer—— geoms(一)

本文介绍了ggplot2图层中的几何对象(geoms),包括geom_abline, geom_hline, geom_vline(参考线)、geom_bar, geom_col, stat_count(条形图)、geom_bin2d, stat_bin_2d(2d bin计数的热图)、geom_blank(空图)和geom_boxplot, stat_boxplot(盒式图)。详细阐述了各种geom的函数格式及参数控制,为后续深入讲解奠定了基础。" 123735252,13009483,1080P实时音视频直播实践:500ms低延迟技术揭秘,"['实时音视频', '视频编解码', '网络传输', 'c++', '开发语言']
摘要由CSDN通过智能技术生成

上次讲到了一些基础知识,这次说一说ggplot2图层中的geoms,由于geoms内容太多,所以分6次说。
图层结合了数据,映射,几何(对象),统计(变换)和位置调整。通常,将使用geom_函数创建图层,如果需要,覆盖默认位置和stat。


1. geom_abline 、geom_hline 、geom_vline——参考线:水平,垂直和对角线

2. geom_bar 、geom_col 、stat_count——条形图

3. geom_bin2d 、stat_bin_2d ——2d bin计数的热图

4. geom_blank——空图

5. geom_boxplot 、stat_boxplot——盒式图


###1. geom_abline 、geom_hline 、geom_vline——参考线:水平,垂直和对角线

函数格式:

geom_abline(mapping = NULL, data = NULL, ..., slope, intercept,
  na.rm = FALSE, show.legend = NA)

geom_hline(mapping = NULL, data = NULL, ..., yintercept, na.rm = FALSE,
  show.legend = NA)

geom_vline(mapping = NULL, data = NULL, ..., xintercept, na.rm = FALSE,
  show.legend = NA)
 Argument
library(devtools)
#install_github("easyGgplot2", "kassambara")
library(easyGgplot2)
p <- ggplot(mtcars, aes(wt, mpg)) + geom_point()
ggplot2.multiplot(p + geom_vline(xintercept = 5),p + geom_vline(xintercept = 1:5),p + geom_hline(yintercept = 20), cols=3)

这里写图片描述


plot1 <- p + geom_abline() # Can't see it - outside the range of the data
plot2 <- p + geom_abline(intercept = 20)
coef(lm(mpg ~ wt, data = mtcars))
#> (Intercept)          wt 
#>   37.285126   -5.344472 
plot3 <- p + geom_abline(intercept = 37, slope = -5)
plot4 <- p + geom_smooth(method = "lm
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值