Does ggplot2 histogram change graph when using facet_grid?

I am trying to bow my head why the histogram using qplot changes when I add facet_wrap. You can find the data that I used for this example here

The factors in my facet_grid come from using cut:

library(ggplot2)
data <- read.csv("data.csv")
data$cuts <- cut(data$y, c(0, 50, 100, 500, Inf))

So now I have this:

> 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                  

If I look only at the section where cuts=="(0,50]", it looks fine .:

qplot(x, data=subset(data, cuts=="(0,50]"))

But when I add the facet grid, the y axes are wrong:

qplot(x, data=data) + facet_grid(cuts~., scales="free_y")

Note that the y-axis on the upper side is now equal to 40 and less than 450. The only line that seems correct (500,Inf].

edit: I am using ggplot 0.9.0 in R 2.14.2

+3
source share
2 answers

ggplot 9.1 , . ggplot2 0.9.1.

right geom_histogram, : geom_histogram(binwidth = 0.2, right = TRUE) +

+3

, ggplot facet_grid " ", . , do-nothing,

data$index = seq.int(1,1000,1)

, , .

+1

All Articles