I am trying to geom_line
plot such that each ID
get its own line. However, the current produces vertical lines instead of horizontal lines.
I already looked here and here and here for help but still can't figure out what I am doing wrong.
How can I fix this in R
?
Sample data and code
ID = c("279557", "279557","279557", "279557", "280485", "280485", "280485", "280485")
Var1 = c("1000", "1500", "2000", "3000", "1100", "1700", "2900", "3500")
Var2 = c("3500", "4800", "5500", "6800", "3800", "5800", "6500", "7800")
library(tidyverse)
df = data.frame(ID, Var1, Var2)
df= df%>%
pivot_longer(-c(ID))
df %>%
ggplot(aes(x = ID, y = value, group = ID)) +
geom_line(size = 1) +
labs(x = "ID",y = "value")
Output
Desired output