I wish to rotate a ggplot2 legend 90°
From
qplot(mpg, wt, data=mtcars, colour=cyl)
生产
类似于:
p <- qplot(mpg, wt, data=mtcars, colour=cyl)
p + scale_colour_continuous(guide = guide_legend(direction = "horizontal", title.position = "top",
label.position="bottom", label.hjust = 0.5, label.vjust = 0.5,
label.theme = element_text(angle = 90))) +
theme(legend.position = c(0.5, 0.9))
Ref: ggplot docs
你可以尝试这个方法
library(ggplot2)
qplot(mpg, wt, data=mtcars, colour=cyl) + theme(legend.position = "top")
guide_legend
内使用label.theme
和title.theme
。 我认为使用title.position =“left”
更好。library(ggplot2)
qplot(mpg, wt, data=mtcars, colour=cyl) +
scale_colour_continuous(guide = guide_legend(direction = "horizontal", title.position = "left", title.theme = element_text(angle = 90),
label.position="bottom", label.hjust = 0.5, label.vjust = 0.5,
label.theme = element_text(angle = 90))) +
theme(legend.position = c(0.5, 0.9))
guide = guide_legend(...
似乎会将键从连续变为离散吗? - user20650