ggplot(mtcars, aes(wt, qsec)) +
geom_point(
aes(
size = mpg
)) +
labs(x = "", y = "", title = 'This is title', subtitle = 'This is subtitle') +
guides(size = guide_legend(nrow = 1)) +
theme(
panel.border = element_blank(),
legend.position = 'top',
legend.justification = 'left',
plot.title = element_text(size = 18),
)
我将标题和图例都设置为左上角,但它们显示左上角的方式似乎不同。感觉标题位于整个图像的左上角,但图例位于绘图区域的左上角,因此它们没有水平对齐
后来我在themes()中定义了legend.position,但这会使绘图区域变得模糊,看起来不太好
ggplot(mtcars, aes(wt, qsec)) +
geom_point(
aes(
size = mpg
)) +
labs(x = "", y = "", title = 'This is title', subtitle = 'This is subtitle') +
guides(size = guide_legend(nrow = 1)) +
theme(
panel.border = element_blank(),
legend.position = c(-0.01,0.9),
legend.justification = 'left',
plot.title = element_text(size = 18),
)
我希望你能帮我
1条答案
按热度按时间dfddblmv1#
您可以将
legend.margin
设置为具有负的左侧边距。创建于2023年3月3日,使用reprex v2.0.2