我希望将ggplot2图例旋转90°
这
qplot(mpg, wt, data=mtcars, colour=cyl)
生产
答案 0 :(得分:3)
类似的东西:
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))
参考:ggplot docs
答案 1 :(得分:3)
你可以试试这个
library(ggplot2)
qplot(mpg, wt, data=mtcars, colour=cyl) + theme(legend.position = "top")
答案 2 :(得分:0)
要完全正确,我认为您需要在label.theme
中使用title.theme
以及guide_legend
。我认为使用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))