R 在ggplot2中旋转图例

R 在ggplot2中旋转图例,r,plot,ggplot2,R,Plot,Ggplot2,我希望将ggplot2图例旋转90° 从 产生 类似于: 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,

我希望将ggplot2图例旋转90°

产生

类似于:

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))
p你可以试试这个

library(ggplot2)
qplot(mpg, wt, data=mtcars, colour=cyl) + theme(legend.position = "top")

为了完全正确,我认为您需要使用
label.theme
以及
title.theme
内部
guide\u legend
。我认为使用
title.position=“left”
更好

(复制粘贴以前解决方案的部分)


您知道为什么使用
guide=guide\u图例(…
似乎会将键从连续变为离散吗?这是因为图例是离散的-您需要
guide\u颜色条。
library(ggplot2)
qplot(mpg, wt, data=mtcars, colour=cyl) + theme(legend.position = "top")
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))