Reputation: 65
I have data which represent the results of a conducted experiment that I want to plot using R. I am retentively new to R and my information are limited. My data are stored in pairs (mean and standard deviation) for each of the experimented methods using different number of examples. For example:
Method A Method B Method C
Mean StDv Mean StDv Mean StDv
1 54.113, 3.469, 51.039, 0.774, 96.257, 1.861
2 55.432, 3.78, 51.921, 1.109, 90.705, 1.284
3 57.047, 3.673, 52.397, 1.054, 90.616, 1.122
4 58.338, 3.919, 53.152, 1.348, 91.024, 0.811
Where 'Mean' and "StDv' is the mean and standard deviation respectively. Moreover, the first column (1, 2, 3, and 4) represents the size of the experimented data. In other words, when the size of the data was 2, the first method scored 55.432 ± 3.78 and the second scored 51.921 ± 1.109 and so on.
The plot that I am after is having the values of the data size (the first column) as the labels of the x-axes, whilst the value of the y-axes are clearly represents the performance (between 0-100) that is the average (or the mean in the table) scored value. Moreover, I want to add the standard deviation to the plot as an error bar. I don't mind if the plot is a bar- or line-chart either will do.
Upvotes: 1
Views: 169
Reputation: 1866
Concerning your specific problem:
You will want to format your data as a data.frame
with columns size, mean, stdv and method (melt
from reshape2
should help you for this). Then you can run code like this below:
p <- ggplot(data, aes(x=size, y=mean, fill=method))
p <- p + geom_bar(position=position_dodge(), stat="identity")
p <- p + geom_errorbar(aes(ymin=mean-stdv , ymax=mean+stdv), width=.2, position=position_dodge(.9))
print(p)
For options and details, these links should help you:
http://www.cookbook-r.com/Graphs/Plotting_means_and_error_bars_(ggplot2)/#bar-graphs
Placement of error bars in barplot using ggplot2
Upvotes: 1