R 在包含0值的xaxis直方图中设置限制

R 在包含0值的xaxis直方图中设置限制,r,ggplot2,histogram,limits,R,Ggplot2,Histogram,Limits,这是我的子集数据,我用突出显示的0值绘制直方图,并绘制正态分布: values <- c(25.222222, 6.000000, 2.057143, 0.000000, 2.142857, 0.000000, 73.666667, 4.081081, 43.133333, 18.937500, 60.822222, 23.379310, 54.954412, 8.492308, 67.646250, 15.885000, 38.585859, 46.810606, 31.565152,

这是我的子集数据,我用突出显示的0值绘制直方图,并绘制正态分布:

values <- c(25.222222, 6.000000, 2.057143, 0.000000, 2.142857, 0.000000, 73.666667, 4.081081, 43.133333, 18.937500, 60.822222, 23.379310, 54.954412, 8.492308, 67.646250, 15.885000, 38.585859, 46.810606, 31.565152, 39.813889, 40.620000, 25.958000, 54.821429, 9.000000, 33.040476, 50.329670, 43.525641, 33.508696, 34.265385, 57.003544, 36.690434, 48.074074, 70.372222, 77.602564, 29.997436, 71.739683, 11.320000, 2.938776, 10.101562, 35.037956)

df <- data.frame(variable = "TH_part", value=values)

ggplot(df, aes(value)) + 
    geom_histogram(aes(fill = value==0), colour = "black", binwidth = 10, position="stack") + 
    scale_x_continuous(breaks = seq(0, 140, by = 20)) + 
    theme_bw() + 
    stat_function(fun=function(value, mean, sd) 10*nrow(df)*dnorm(value, mean, sd), 
                  args=fitdistr(df$value, "normal")$estimate)


我不明白,因为0仍然在我的限制范围内。xaxis是否有另一个控制语句?

可能会将限制设置为
c(NA,140)
是的,确实!简单的解决方案,谢谢。
ggplot(df, aes(value)) + 
    geom_histogram(aes(fill = value==0), colour = "black", binwidth = 10, position="stack") + 
    scale_x_continuous(breaks = seq(0, 140, by = 20), limits = c(0,140)) + 
    theme_bw() + 
    stat_function(fun=function(value, mean, sd) 10*nrow(df)*dnorm(value, mean, sd), 
                  args=fitdistr(df$value, "normal")$estimate)