문제

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