【发布时间】:2012-05-09 18:43:28
【问题描述】:
我试图弄清楚为什么当我添加 facet_wrap 时使用 qplot 的直方图会发生变化。你可以找到我在这个例子中使用的数据here
我的 facet_grid 中的因素来自使用cut:
library(ggplot2)
data <- read.csv("data.csv")
data$cuts <- cut(data$y, c(0, 50, 100, 500, Inf))
所以现在我有了这个:
> summary(data)
y x cuts
Min. : 10.00 Min. :0.000 (0,50] :530
1st Qu.: 20.75 1st Qu.:1.000 (50,100] :179
Median : 46.00 Median :1.000 (100,500]:258
Mean : 110.18 Mean :0.834 (500,Inf]: 33
3rd Qu.: 121.00 3rd Qu.:1.000
Max. :1526.00 Max. :1.000
如果我只看cuts=="(0,50]" 所在的部分,它看起来很好。:
qplot(x, data=subset(data, cuts=="(0,50]"))
但是当我添加分面网格时,y轴都是错误的:
qplot(x, data=data) + facet_grid(cuts~., scales="free_y")
请注意,顶部刻面的 y 轴现在只有 40ish 而不是超过 450。唯一看起来正确的刻面是 (500,Inf]。
编辑:我在 R 2.14.2 中使用 ggplot 0.9.0
【问题讨论】: