I have a dataset like this
Date location count
18-01-2023 A 38.457
18-01-2023 B 0
24-01-2023 C 0
24-01-2023 A 0
24-01-2023 C 0
27-01-2023 B 35.22
27-01-2023 A 0
27-01-2023 B 0
01-02-2023 A 0
01-02-2023 B 38.78
01-02-2023 C 0
01-02-2023 D 0
03-02-2023 B 0
03-02-2023 A 0
03-02-2023 C 35.789
03-02-2023 D 0
I want to create a plot where X axis is Date and Y axis is count and 4 different lines will be plotted with different colours for different location A, B, C and D.
demo image :
I have tried this command
library(lubridate)
library(dplyr)
library(ggplot2)
df<-all_data
df |>
dplyr::mutate(
Date=dmy(Date),
count=as.numeric(count))|>
ggplot(aes(x=Date, y=count, color=Location,group=Location)) +
geom_line()+
geom_point()
but its not working .
can anybody please help .
What error are problem are you having?
Error in as.character(x) : cannot coerce type 'closure' to vector of type 'character'
Please provide reproducible example data:
dput(head(df))
, check the structure of your data,str(df)
. There is a typo on column name, too location vs Location.