Rdates <- c(\"2007-01-31\",\"2007-02-28\",\"2007-03-30\",\"2007-04-30\",\"2007-05-31\",\"2007-06-29\",\"2007-07-31\",\"2007-08-31\",\"2007-09-28\",\"2007-10-31\")
You were really close. Try this at the very end:
gg+guides(fill=guide_legend(nrow=2,byrow=TRUE))
The solution above is presented for a single aesthetic. In some cases, you may want to wrap the legend into rows instead of columns across different aesthetics. For posterity, this is shown below.
library(ggplot2)
ggplot(diamonds, aes(x=carat, y=price, col=clarity, shape=cut)) +
geom_point() +
theme(legend.position="bottom")
The legend is cut off below:
To wrap the legend using rows, we specify legend.box="vertical"
. Below, we also reduce the margin for compactness.
ggplot(diamonds, aes(x=carat, y=price, col=clarity, shape=cut)) +
geom_point() +
theme(legend.position="bottom", legend.box="vertical", legend.margin=margin())