Using R ggplot2 library, I an generating a facet_grid plot and I want to put a legend off to the right hand side of all the plots -NOT EACH INDIVIDUAL PLOT, but one legend that works for all the plots
g = ggplot(pd2, aes(x = p/1000, y=c/1000 )) +
geom_point(alpha=.1, colour="red") +
geom_smooth(method=lm) +
xlab("Ave P") +
ylab("Ave C)") +
labs(title = "Comparison ") +
theme(plot.title = element_text(face="bold",
size=14, colour="black", hjust = 0.5)) +
theme(axis.title = element_text(face="bold", size=12, colour="blue")) +
facet_grid(code ~ TheState) +
theme(strip.text.y = element_text(colour = "purple", angle = 0,
size = 9, hjust = 0.5, vjust = 0.5))
What I want to do is have a legend off to the right that is turned 90 degrees - because I want the legend to refer to very_long_code instead of just "code." I've tried all kinds of variations of legend, theme, and guide. Intuitively, I would like to say,
legend(text, angle=90, very_long_code, color="purple")
The next step would be to not use a single color, but to use a different color for each one that would correspond to colors in the strip.