ggplot 2 做箱线图(二)

箱线图之分面

1.数据整理格式如下:
ggplot 2 做箱线图(二)_第1张图片

qplot(pH, contents, fill=type, data=Lin1, geom=c(“boxplot”))
ggplot 2 做箱线图(二)_第2张图片
abc <- qplot(pH, contents, fill=type, data=Lin1, geom=c(“boxplot”))
abc + facet_grid(type ~.)
ggplot 2 做箱线图(二)_第3张图片
abc + facet_grid(type ~. , scales = “free_y”)
ggplot 2 做箱线图(二)_第4张图片

  1. 完整代码:
    qplot(pH, contents, fill=type, data=Lin1, geom=c(“boxplot”))
    abc <- qplot(pH, contents, fill=type, data=Lin1, geom=c(“boxplot”))
    abc + facet_grid(type ~.)
    abc + facet_grid(type ~. , scales = “free_y”)

  2. abc + facet_grid(type ~.)
    facet_grid 是分面函数
    type~. :横着分面【一列多行展示,横坐标相同,用于x 位置的比较】
    .~ type:竖着分面【一行多列展示,纵坐标相同,用于y 位置的比较】

  3. abc + facet_grid(type ~. , scales = “free_y”)
    scales 是设置坐标轴刻度线的设置
    scales=“free_y”, y轴自由设置;
    scales=“free_x”, x轴自由设置

OVER~~~~~

你可能感兴趣的:(ggplot 2 做箱线图(二))