I struggle with putting the abline in the legend. It works fine with the points and their colour, but as far as I succeed is the six lines overlapping with the points... Can I just somehow add another legend element with the black line labeled as "LMWL"? I know that I can post-edit this in Corel or any software but I would like to do it in the code...
ggplot(df_merge_iso, aes(x = d18O, y = d2H, color = category, shape = category, label = month)) +
labs(
x = expression(paste(delta^{18}, "O (\u2030)")),
y = expression(paste(delta^{2}, "H (\u2030)"))) +
geom_point(size = 1, stroke = 1) +
theme_minimal() +
theme(
axis.text = element_text(size = 12, color = "black"),
axis.title = element_text(size = 12, color = "black")
) +
scale_color_manual(
name = "",
values = c(
"A" = "#0015f0",
"B" = "#6AC4FF",
"C" = "#4B8CEB",
"D" = "#FF7E5F",
"E" = "#FFB300",
"F" = "#E75007"
)) +
scale_shape_manual(
name = "",
values = c(
"A" = 2,
"B" = 1,
"C" = 21,
"D" = 3,
"E" = 4,
"F" = 6
)) +
geom_text_repel(
vjust = -1, hjust = 0.5, size = 2, show.legend = FALSE,
box.padding = 0.2
) +
geom_abline(slope = lmwl_slope_wgt, intercept = lmwl_intercept_wgt,
colour = "black", linetype = "solid", size = 0.5)
If you want a legend you have to map on aesthetics. In case you want to add a legend entry to the already present
colorandshapelegend you could do by mapping e.g. the constant"LMWL"oncolorandshapeingeom_ablinewhich also requires to moveinterceptandslopeinsideaes(). Additionally you have to provide a color and a shape for LMWL in the scales.Using some fake example data:
If you want a separate legend you could fake one by mapping e.g. on the
linetypeaes: