我有以下数据和图片设置如下所示
df <- data_frame(group = rep(c("A", "B"), each = 20),
y = c(sample(1:90, 20, replace = TRUE),
sample(1:30, 20, replace = TRUE)),
x = rep(1:20, 2)
)
ggplot(df, aes(x = x, y = y, color = group))+
geom_line()+
labs(x = "", y = "", title = "Comparison",
subtitle = "Unit (thousand)",
caption = "Source: Kaggle")+
theme(legend.title = element_blank(),
legend.position = "top",
legend.justification='left',
legend.box = "horizontal",
legend.key = element_blank(),
legend.box.margin = margin(0,0,0,0,"cm"),
plot.title.position = "plot",
plot.caption.position = "plot",
plot.caption = element_text(hjust = 0))
并在这里生成图表:
如何将图例框移动到绘图区的最左侧,并与标题和副标题对齐?还必须考虑到legend.key中的边距。
如果您能告诉我如何减少图例周围的空间,我将不胜感激。谢谢!