0

How can I compare 2 years with ggplot2 in R?

I have a data set which is like:

month: num 2 4 6 8 10 11 12 1
year:  factor 2018 2019 2018 2019
value: num 1000 11555 111220 14445 

I need to compare these 2 years over the months in a plot.
my x axis needs to be month
my y axis needs to be value
and my lines needs to be the years values.

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
  • What have you tried so far? Why didn't it meet your needs? – Limey Jun 05 '20 at 07:12
  • 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 Jun 05 '20 at 07:32

1 Answers1

0

I tried to reproduce your data in a way that was tangible. This is not an accurate representation of your data because it is unclear how the actual data frame looks like

    month<- c(2,4,6,8,10,11,12,1)
year<-  c(2018,2019,2018,2019)
value<- c(1000,11555,111220,14445)
x <- data.frame("month" = month, "year" = year, "value" = value)

ggplot(data = x, aes(x = month, y = value, group =1))+
  geom_line()+
  geom_point()
Kdiddledoo
  • 11
  • 2