Question

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")
Was it helpful?

Solution

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")

OTHER TIPS

When you create your legend, you can use the argument 'horiz' which is automatically at FALSE

legend( ... , horiz=TRUE)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top