I would like to combine a line plot and a scatter plot in one graph. The data comes from different data frames and the columns have different names. This is my reproducible example, which throws an error:
library(ggplot2)
x <- runif(1000, min = 0, max = 100)
y <- rnorm(1000, mean = 50, sd = 30)
df1 <- data.frame(
x = x
, y = y
)
x1 <- runif(10, min = 0, max = 100)
y1 <- rnorm(10, mean = 50, sd = 30)
df2 <- data.frame(
x1 = x1
, y1= y1
)
ggplot(df1, aes(x, y)) +
geom_line() +
geom_point(df2, aes(x1, y1))

geom_point(aes(x1, y1), df2). Layers (eg.,geom_point) have different argument ordering than mainggplotcall (ie, in layersaesgoes first).