You get horizontal legend by adding argument legend.direction="horizontal"
inside the theme()
or opts()
theme(legend.direction="horizontal")
Older versions
opts(legend.direction="horizontal")
Domanda
I'd like the legend inside the plot to be horizontal (each one is beside each other not one is above the other)
Is there a way to change from vertical to horizontal? Example:
mtcars$cyl <- factor(mtcars$cyl, labels=c("four","six","eight"))
ggplot(mtcars, aes(x=wt, y=mpg, colour=cyl)) + geom_point(aes(colour=cyl)) +
opts(legend.position = c(0, 1), title="Legend placement makes me sad")
Soluzione
You get horizontal legend by adding argument legend.direction="horizontal"
inside the theme()
or opts()
theme(legend.direction="horizontal")
Older versions
opts(legend.direction="horizontal")
Altri suggerimenti
When you create your legend, you can use the argument 'horiz' which is automatically at FALSE
legend( ... , horiz=TRUE)