0

I created two different plots using ggplot2. Is there a way to overlap these two plots in the same axes? enter image description here and enter image description here

nikn8
  • 1,016
  • 8
  • 23
  • 2
    Welcome to Stack Overflow! Could you make your problem reproducible by sharing a sample of your data so others can help (please do not use `str()`, `head()` or screenshot)? You can use the [`reprex`](https://reprex.tidyverse.org/articles/articles/magic-reprex.html) and [`datapasta`](https://cran.r-project.org/web/packages/datapasta/vignettes/how-to-datapasta.html) packages to assist you with that. See also [Help me Help you](https://speakerdeck.com/jennybc/reprex-help-me-help-you?slide=5) & [How to make a great R reproducible example?](https://stackoverflow.com/q/5963269) – Tung May 26 '20 at 05:13

1 Answers1

0

When you first learn to make a ggplot(), you'll start by putting the data and aesthetics in the ggplot() function and then adding the layers using this data and aesthetics, e.g.

ggplot(df1, aes(x1,y1)) +
geom_line() +
geom_point()

However, you can supply the data and aesthetics for each layer if you need to, eg

ggplot() +
geom_line(aes(x1,y1), data= df1) +
geom_point(aes(x1,y1), data= df1)

Which also means, you can use different data and aesthetics in each layer, eg

ggplot() +
geom_line(aes(x1,y1), data= df1) +
geom_line(aes(x2,y2), data= df2)