0

I have this data frame

county    |    date    |   type   | value
-----------------------------------------
Alameda    2020-01-01      masks     1
Alameda    2020-01-02      masks     3
Alameda    2020-01-03     closure    4
Alameda    2020-01-04     closure    7

I want to plot in the x axis the date and in the y axis the value but for each different "type" (masks, closure) make different lines but in the same graph. How Can I do this?

Thank you

coding
  • 917
  • 2
  • 12
  • 25

1 Answers1

0

We can specify the color in ggplot

library(ggplot2)
ggplot(df1, aes(x = date, y = value, color = type)) + 
        geom_line()

-output

enter image description here

data

df1 <- structure(list(county = c("Alameda", "Alameda", "Alameda", "Alameda"
), date = structure(c(18262, 18263, 18264, 18265), class = "Date"), 
    type = c("masks", "masks", "closure", "closure"), value = c(1L, 
    3L, 4L, 7L)), row.names = c(NA, -4L), class = "data.frame")
akrun
  • 874,273
  • 37
  • 540
  • 662