Reputation: 4772
How can I create a legend informing that the red cross is the mean?
ggplot(results, aes(x=factor, y=proportionPositive)) +
geom_boxplot() +
stat_summary(fun.data = "mean_cl_normal", colour = "red", shape=4)
Upvotes: 19
Views: 13300
Reputation: 21
for me option "show.legend=TRUE" simply did work out:
ggplot(aes(x=stimulus, y=EPN, fill=strategy))+
stat_summary(fun.data=mean_se, show.legend=TRUE, geom="bar", position="dodge", colour="black", linetype="solid", size=0.3)
Upvotes: 1
Reputation: 1536
To make it appear like a default legend (borrowing from @Andrie code):
ggplot(results, aes(x=factor, y=proportionPositive)) +
geom_boxplot() +
stat_summary(fun.data = "mean_cl_normal",
aes(shape=""), # Leave empty
colour = "red",
geom="point") +
scale_shape_manual("mean", values= "") # Will show mean on top of the line
Upvotes: 0
Reputation: 179398
Here is one way of doing it:
# Create dummy data results <- data.frame( factor=factor(rep(1:10, 100)), proportionPositive=rnorm(1000)) # Plot results ggplot(results, aes(x=factor, y=proportionPositive)) + geom_boxplot() + stat_summary(fun.data = "mean_cl_normal", aes(shape="mean"), colour = "red", geom="point") + scale_shape_manual("", values=c("mean"="x"))
Upvotes: 28