ggplot2数据分析与图形艺术-重点归纳(第3章后续)
2020-01-30 本文已影响0人
MJades
Statistical summaries
Revealing uncertainty
- Discrete x, range: geom_errorbar(), geom_linerange()
- Discrete x, range & center: geom_crossbar(), geom_pointrange()
- Continuous x, range: geom_ribbon()
- Continuous x, range & center: geom_smooth(stat = "identity")
identity: 一个x对应一个y,提取横坐标x对应的y; bin: 提取横坐标x频数
Weighted data 参数weight
- For more complicated grobs which involve some statistical transformation, we specify weights with the weight aesthetic. These weights will be passed on to the statistical summary function. Weights are supported for every case where it makes sense: smoothers, quantile regressions, boxplots, histograms, and density plots.
# Unweighted
ggplot(midwest, aes(percwhite, percbelowpoverty)) +
geom_point() +
geom_smooth(method = lm, size = 1)
# Weighted by population
ggplot(midwest, aes(percwhite, percbelowpoverty)) +
geom_point(aes(size = poptotal / 1e6)) +
geom_smooth(aes(weight = poptotal), method = lm, size = 1) +
scale_size_area(guide = "none")
Displaying distributions
- geom_histogram(aes(fill=cut ),position="fill")
-
geom_bar, geom_violin 可以通过设定cut_width() 对连续型变量进行分组可视化。
Fig 1
Dealing with overplotting
改变点的大小(像素点大小),调整透明度, 增加扰动点(geom_jitter), 转化为二维核密度估计问题,在图形基础之上增加数据摘要。
shape= 1 # 中空点;
shape= “.” # 像素大小

