0

I am trying to plot a multiple line graph, with different colors and the legend in R, without much success... I have a data frame named DatProv <- (DatProv$Date, DatProv$Test1, DatProv$Test2, DatProv$Test3) as follows (simplified):

Date.          Test1.       Test 2.      Test 3
2020-02-01.     1.            0.           1
2020-03-31.     1.            1.           1
2020-04-05.     5.            3.           3
2020-05-01.     20.           23.          17

I would like to plot in x-axis the Date (which is in date format %Y-%m-%d, but if possible get the months (feb, mar, apr, may)) against Test1, Test 2 and Test 3 (they are integers).
I tried the ggplot but didn't get at all what I expected which is basically 3 time series showing the evolution of the three tests against the date.

Any help would be much appreciated! Thanks!

1

1 Answer 1

1

Please don't share images of data tables as part of the question. In the future you can use the dput() function to generate a sharable version of your data. For example: dput(DatProv)

Does this code below produce what you're looking for?

library(tidyverse)

DatProv %>%
  pivot_longer(cols = starts_with('Test'),
               names_to = 'Test',
               values_to = 'Value') %>%
  ggplot(aes(lubridate::date(date), Value, color = Test, group = Test)) +
  geom_line() +
  scale_x_date(date_breaks = '1 month',
               date_labels = '%b')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.