ggplot2 add legend for each geom_point manually
Posted
by
user1162769
on Stack Overflow
See other posts from Stack Overflow
or by user1162769
Published on 2012-10-22T22:56:44Z
Indexed on
2012/10/22
23:00 UTC
Read the original article
Hit count: 152
ggplot2
I created a plot using 2 separate data sets so that I could create different errorbars. The first data set has error bars that go down only whereas the second data set has error bars that go up only. This prevents unnecessary overlap in the plot. I also used a compound shape for one of the groups.
I want to create a legend based on these shapes (not a colour), but I can't seem to figure it out. Here is the plot code.
p<-ggplot()
p + geom_point(data=df.figure.1a, aes(x=Hour, y=Mean), shape=5, size=4) +
geom_point(data=df.figure.1a, aes(x=Hour, y=Mean), shape=18, size=3) +
geom_errorbar(data=df.figure.1a, aes(x=Hour, y=Mean, ymin = Mean - SD, ymax = Mean), size=0.7, width = 0.4) +
geom_point(data=df.figure.1b, aes(x=Hour, y=Mean), shape=17, size=4) +
geom_errorbar(data=df.figure.1b, aes(x=Hour, y=Mean, ymin = Mean, ymax = Mean + SD), size=0.7, width = 0.4)
© Stack Overflow or respective owner