Вопрос

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")
Это было полезно?

Решение

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

Другие советы

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

legend( ... , horiz=TRUE)
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top