Using the legend.box feature of ggplot, I want to integrate multiple aes legends into one box. However, I cannot seem to figure out how to organize the legend box.
In this example:
library(ggplot2)
dat <- data.frame(x=c(1,2,3),y=c(5,7,3))
p <- ggplot() +
geom_col(data=dat,aes(x,y,fill="test col")) +
geom_point(data=dat,aes(x,y,shape="test point")) +
geom_line( data=dat,aes(x,y,linetype="test line")) +
theme(legend.position="top",
legend.justification = "center",
legend.background = element_blank(),
legend.box.background = element_rect(fill="gray90", size=.5, color=NA))
p
gives a line (which I cannot find how to wrap over multiple lines).
p + theme(legend.box = "vertical")
is currently the best solution I could find but is not satisfactory, as I get stuck with a legend that has as many lines as aes.
Can please someone advise on how to wrap the legend box?
Thanks in advance