问题
I have two groups with mean scores and standard deviations which represent how confident we are with the mean estimates. Note: I do not have raw scores, just mean estimates outputted from a model and the SD of the estimates outputted from the model, around that mean.
I have a feature set around 20, and I want to compare for each feature the mean +/- standard deviations of each of my 2 groups. It will essentially look like this:
ggplot() seems to work with data that has the raw data and it calculates the mean and standard deviation from the arrays of each feature. boxplot() works similarly.
Can anyone help me figure out a way to visualize my results in this way?
回答1:
I don't think you want a boxplot in this case. You could use something like geom_errorbar
from the ggplot2
package. Please provide data or sample data to make your question reproducible.
df <- data.frame(means = rnorm(20, 5, 2),
sds = rnorm(20),
feats = c(paste0("Feature ", letters[1:10])),
group = rep(c("group 1", "group 2"), each = 2))
head(df)
# means sds feats group
# 1 7.298374 -1.1545645 Feature a group 1
# 2 6.124870 -0.0694843 Feature b group 1
# 3 3.855704 0.3802556 Feature c group 2
# 4 6.357659 2.2822757 Feature d group 2
# 5 3.572474 -0.9488784 Feature e group 1
# 6 3.526351 2.5956482 Feature f group 1
library(ggplot2)
ggplot(df, aes(x = feats, color = group)) +
geom_errorbar(aes(ymax = means + sds, ymin = means - sds),
position = "dodge")
来源:https://stackoverflow.com/questions/34073179/r-manual-boxplot-with-means-and-standard-deviations-ggplot2