I have an issue with boxplot graphs using ggplot or boxplot function in R. I went through some of the questions here but none of them solve my issue.
I have data set contains 20 samples and ten elements for each. I'm trying to produce box plot so this is what I did so far:
- I have used the melt function to transform the data set into a long format (See picture, is just an example of one element)
NC_RSD.ca.m <- melt(NC_RSD.ca, id.var="Sample")
Here is the example data:
structure(list(Sample = structure(c(15L, 16L, 17L, 18L, 19L,
20L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L,
14L), .Label = c("NC10", "NC11", "NC12", "NC13", "NC14", "NC15",
"NC16", "NC17", "NC18", "NC19", "NC20", "NC21", "NC22", "NC23",
"NC4", "NC5", "NC6", "NC7", "NC8", "NC9"), class = "factor"),
Al = c(21.54055979, 13.89504614, 20.19173286, 15.39846212,
18.6210721, 19.3885953, 17.29371421, 13.85368756, 15.59018781,
14.81984326, 41.64842461, 16.29394917, 14.7150582, 21.12155266,
15.81993475, 11.78606019, 14.1812477, 11.70589836, 14.6093647,
15.21199958), Si = c(21.16836701, 10.10779796, 15.34477311,
18.55455665, 14.33326026, 15.76035258, 5.665395745, 5.775772135,
15.50099702, 8.054620606, 26.59536241, 13.85935577, 12.58568469,
18.7485275, 20.28945667, 6.650252061, 13.83863564, 7.741041704,
10.27977138, 9.224247111), S = c(205.4330401, 57.11209582,
93.85434886, 100.70889, 58.09909663, 40.44801629, 30.18807909,
45.30207695, 23.9134537, 30.28300595, 33.88869256, 45.03864953,
59.74444561, 39.75414202, 20.63363293, 14.07988915, 28.43671918,
77.72186352, 22.08674507, 35.25044782)), class = "data.frame", row.names = c(NA,
-20L))
- when I used the ggplot to produce boxplot using the following line:
ggplot(data = NC_RSD_ca.m, aes(x= Sample, y=value, group = value)) + geom_boxplot(aes(fill = variable)
the result is just flat lines!
My question is what I have to do to show the boxplot correctly.
I'm trying to produce a similar plot as this image:
your help is appreciated, and thank you in advance.