1

I'm trying to make a histogram of my data with standard deviation; data which looks like this:

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

And my code is this:

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

The code gives me an empty graph. What would you suggest me to do?

Richard Telford
  • 9,558
  • 6
  • 38
  • 51
Mel
  • 11
  • 5
  • 2
    Suggest you take a look at `data2` to see what values you actually got for `mean1`. – Z.Lin Sep 09 '17 at 09:46
  • Hello, thanks for your help. I checked data2 and it gives the right values. I think the problem is in the plot but I'm not sure what. Because the histogram my data provides is empty but the x axis gives a mean value around 17. Therefore, it should've read the data. – Mel Sep 10 '17 at 09:04
  • Please share `data2` in [reproducible form](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). It would help us troubleshoot. – Z.Lin Sep 10 '17 at 10:50

1 Answers1

1

You have binwidth=1 this creates a single histogram bar. Change your code to

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

and it will work fine.

B Williams
  • 1,992
  • 12
  • 19