I have the following data and picture setup as below
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))
and generate the graph here:
How to move legend box all the way to the left of the plot and align with titles and subtitles? Also have to taken into account that there's a margin in legend.key.
Also appreciated it if you can let me know how to reduce the space around legend as well. Thanks!


