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