So, here is my issue.
I have data similar to the minimal reproducible example below that I want to plot with ggplot2, where a data frame contains one column that I want to use as the x-values for every geom and several columns that I want as different y-values. As you can see from the example below, I want to combine geom_line and geom_point with different shapes for the geom_point values.
My question now is, how do I insert a legend that tells me what columns which shape represents. From what I have learned about ggplot2 so far, a legend is usually generated, if I map some factor (might not be the correct term) to color = or group =, I am wrong? So how can I still get a legend without that prerequisite?
Help is much appreciated!
library(tidyverse)
df <- structure(list(rep = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1), Y_1 = c(0.0198, 0.0108, 0, 0.0117, 0.00931, 0.0089, 0.0115,
0.00509, 0.00831, 0.0158, 0.0437, 0.0953, 0.267, 0.677, 1.81),
Y_2 = c(0.025, 0.00249, 0.00303, 0.00268, 0.0102, 0.0112,
0.0231, 0.0326, 0.0575, 0.0852, 0.143, 0.219, 0.384, 0.687,
1.01), X = c(0.1, 0.164, 0.268, 0.439, 0.72, 1.18, 1.93,
3.16, 5.18, 8.48, 13.9, 22.8, 37.3, 61.1, 100)), row.names = c(NA,
15L), class = "data.frame")
df_plot <- ggplot(data = df) +
geom_line(mapping = aes(x = X, y = Y_1)) +
geom_point(mapping = aes(x = X, y = Y_1), shape = 15) +
geom_line(mapping = aes(x = X, y = Y_2)) +
geom_point(mapping = aes(x = X, y = Y_2), shape = 0) +
scale_x_log10() +
scale_y_log10() +
theme_classic()
df_plot
