2017-09-09 19 views
1

我試圖用標準差作出我的數據的直方圖;數據看起來像這樣:空結果的直方圖

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") 

代碼給我一個空圖。你會建議我做什麼?

+2

建議您查看'data2'來查看'mean1'的實際值。 –

+0

你好,謝謝你的幫助。我檢查了data2,它給出了正確的值。我認爲問題在於情節,但我不確定是什麼。由於我的數據提供的直方圖是空的,但x軸的平均值在17左右。因此,它應該讀取數據。 – Mel

+0

請以[可重現的形式]分享'data2'(https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)。這將幫助我們排除故障。 –

回答

1

您有binwidth=1這會創建一個直方圖欄。將您的代碼更改爲

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

它會正常工作。

+0

它的工作,非常感謝你! – Mel