工具箱














工具箱





















基本图形类型

  • 图形属性
    • colour,
    • size,
    • fill,
    • shape,
    • linetype
  • 基本图形
    • geom_area(),面积图,对于分组数据将按照依次堆积的方式绘制
    • geom_bar(stat= “identity”)
    • geom_line(),group决定了哪些观测是链接在一起的
    • geom_polygon()绘制多边形,即填充后的路径图
    • geom_text()在指定处添加标签,需要指定label参数,hjust,vjust,angle来调整纵横位置和角度
    • geom_tile()绘制色深图或水平图

展示数据分布

一维连续分布用直方图,设置组距宽度(binwidth),或指定切分位置(breaks) 分组比较用分面

library(ggplot2)
depth_dist<-ggplot(diamonds,aes(depth))+xlim(58,68)
depth_dist+
  geom_histogram(aes(y=..density..),binwidth=0.1)+facet_grid(cut~.)
## Warning: position_stack requires constant width: output may be incorrect
## Warning: position_stack requires constant width: output may be incorrect
## Warning: position_stack requires constant width: output may be incorrect
## Warning: position_stack requires constant width: output may be incorrect
## Warning: position_stack requires constant width: output may be incorrect

depth_dist+geom_histogram(aes(fill=cut),binwidth=0.1,position = "fill")
## Warning: position_fill requires constant width: output may be incorrect

位置调整参数: dodge,fill,identity,jitter,stack

频率多边形(frequency polygon)

depth_dist+geom_freqpoly(aes(y=..density..,colour=cut))
## stat_bin: binwidth defaulted to range/30. Use 'binwidth = x' to adjust this.
## Warning: Removed 2 rows containing missing values (geom_path).
## Warning: Removed 2 rows containing missing values (geom_path).
## Warning: Removed 2 rows containing missing values (geom_path).
## Warning: Removed 2 rows containing missing values (geom_path).
## Warning: Removed 2 rows containing missing values (geom_path).


你可能感兴趣的:(R,R)