直方图结果为空

时间:2017-09-09 05:47:10

标签: r ggplot2

我试图用标准偏差制作数据的直方图;看起来像这样的数据:

Time   Sample Measurement.1 Measurement.2 Measurement.3
0  Control       16.9117       16.8092       16.9567    
0    Yeast       16.9917       17.0497       17.0697    
0 Bacteria       16.9928       17.2786       16.9393    
3  Control       16.9116       16.8090       16.9559    
3    Yeast       16.9888       17.0488       17.0676    
3 Bacteria       16.9881       17.2780       16.9377

我的代码就是这样:

library(ggplot2)
data = read.csv('Desktop/Meltem.csv')
cols = c(3, 4, 5)

data2 <- transform(data, mean1 = rowMeans(data[, cols]),
                   sd = apply(data[, cols], 1, sd))[, -(3:5)]

plot1 <- ggplot(data2, aes(x = mean1)) + 
    geom_histogram(binwidth = 1,color = "black", fill = "white")

代码给了我一个空图。你建议我做什么?

1 个答案:

答案 0 :(得分:1)

您有binwidth=1这会创建一个直方图条。将您的代码更改为

ggplot(data2, aes(x = mean1)) + geom_histogram(color = "black", fill = "white")

它会正常工作。