0

I'm creating a boxplot on r using ggplot. I created 2 different lines of code and want to put into the same graph to compare data from 2019 and 2020. However, with Youtube videos they say to add "~" anyone know what's wrong?

code I'm using

ggplot(covid, aes(x=covid1$oct2019_rent, y=covid1$Depression.2019))+ geom_boxplot()~ ggplot(covid, aes(x=covid1$oct2020_rent, y=covid1$Depression.2020)) + geom_boxplot()
  • Welcome to SO! Would you mind providing [a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) including a snippet of your data or some fake data. – stefan Dec 16 '21 at 23:51

1 Answers1

0

For this type of job, I use the patchwork package. Your code will be something like.

library(patchwork)

p1 <- ggplot(covid, aes(x=covid1$oct2019_rent, y=covid1$Depression.2019))+ geom_boxplot()
p2 <- ggplot(covid, aes(x=covid1$oct2020_rent, y=covid1$Depression.2020)) + geom_boxplot()

p1 / p2

There are some examples that you can ajust for your needs.

GregOliveira
  • 151
  • 10