Creating multiple line graphs in r

I was trying to make multple line graphs for each of the cause with x as year and y as value
This is my code

Death %>% group_by(year) %>% ggplot(aes(x=year,y=value,fill=Cause)) + geom_point() + geom_line(color=cause)
But it does not work
My data
structure(list(Cause = c("Ischaemic Heart Disease", "Ischaemic Heart Disease",
"Ischaemic Heart Disease", "Pneumonia", "Pneumonia", "Pneumonia",
"Spontenuos ICH", "Spontenuos ICH", "Spontenuos ICH", "Cirrhosis of the liver",
"Cirrhosis of the liver", "Cirrhosis of the liver", "Malignancy",
"Malignancy", "Malignancy", "Sepsis", "Sepsis", "Sepsis", "Others",
"Others", "Others", "Hanging", "Hanging", "Hanging", "Poisoning",
"Poisoning", "Poisoning", "Drowning", "Drowning", "Drowning",
"Others", "Others", "Others", "Motor vehicle -RTA", "Motor vehicle -RTA",
"Motor vehicle -RTA", "Drowning", "Drowning", "Drowning", "Food Aspiration",
"Food Aspiration", "Food Aspiration", "Fallen from height", "Fallen from height",
"Fallen from height", "Electrocution", "Electrocution", "Electrocution",
"Others", "Others", "Others", "Sharp weapon injuries", "Sharp weapon injuries",
"Sharp weapon injuries", "Blunt weapon injuries", "Blunt weapon injuries",
"Blunt weapon injuries", "Fire arm injuries", "Fire arm injuries",
"Fire arm injuries", "Strangulation", "Strangulation", "Strangulation",
"Others", "Others", "Others", "Drowning", "Drowning", "Drowning",
"Others", "Others", "Others"), year = c("2017", "2018", "2020",
"2017", "2018", "2020", "2017", "2018", "2020", "2017", "2018",
"2020", "2017", "2018", "2020", "2017", "2018", "2020", "2017",
"2018", "2020", "2017", "2018", "2020", "2017", "2018", "2020",
"2017", "2018", "2020", "2017", "2018", "2020", "2017", "2018",
"2020", "2017", "2018", "2020", "2017", "2018", "2020", "2017",
"2018", "2020", "2017", "2018", "2020", "2017", "2018", "2020",
"2017", "2018", "2020", "2017", "2018", "2020", "2017", "2018",
"2020", "2017", "2018", "2020", "2017", "2018", "2020", "2017",
"2018", "2020", "2017", "2018", "2020"), value = c(203, 206,
219, 58, 33, 27, 22, 21, 23, 27, 27, 23, 15, 9, 25, 35, 53, 47,
40, 30, 59, 51, 38, 28, 29, 20, 24, 11, 15, 4, 1, 4, 5, 49, 47,
37, 11, 14, 24, 1, 2, 0, 4, 3, 11, 2, 6, 7, 10, 6, 12, 2, 7,
4, 5, 2, 4, 1, 2, 1, 1, 0, 0, 1, 1, 2, 1, 0, 0, 8, 1, 2)), row.names = c(NA,
-72L), class = c("tbl_df", "tbl", "data.frame"))

year should be treated numerically, and no need to group by it.

death %>% mutate(year=as.integer(year)) %>% 
  ggplot(aes(x=year,y=value,color=Cause)) + 
  geom_point() + 
  geom_line() + facet_wrap(~Cause,ncol=3)

This produce seperate graphs I want all of the lines for causes in a one graph

Therefore remove the facet wrap

thanks alot you were alife saver

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.