我用ggplot创建了一张线图。我希望增加图例项之间的垂直间距(文本和符号)
我在这个问题上找到了this。但是,对于这个问题,难道没有更简单的解决方案(即不编写函数)吗?
我尝试了命令legend.spacing.y
,但这只是上下移动整个图例,而不是项目之间的间隔。
另外,我尝试了:theme(legend.text = element_text(margin = margin(t = 1, unit = "cm"))))
,但是,这个只移动文本,而不是项目。
有人能帮忙吗?
谢谢!
发布于 2020-12-11 08:58:36
我们也可以用tidyverse
在管道中实现这一点。
library(ggplot2)
library(dplyr)
mtcars %>%
mutate(cyl = factor(cyl)) %>%
ggplot(aes(mpg, wt, colour = cyl)) +
geom_point() +
theme(
legend.key.size = unit(1.5, 'lines'),
legend.key = element_rect(size = 5, color = 'white'))
发布于 2020-12-11 06:28:53
这可能是有用的:
library(ggplot2)
#Code
ggplot(data = mtcars, aes(mpg, wt, colour = factor(cyl))) +
geom_point() +
theme(
legend.key.size = unit(1.5, 'lines'),
legend.key = element_rect(size = 5, color = 'white'))
输出:
https://stackoverflow.com/questions/65253000
复制相似问题