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.
Desired output
CodePudding user response:
As highlighted in the comments, your data doesn't have an "X" variable. This would typically be something like time or location. Alternatively, manually add one based on the grouped row number. To add the legend, include a mappable value like colour in the aesthetics.
df = df %>%
pivot_longer(-c(ID)) %>%
group_by(ID) %>%
mutate(row = row_number())
df %>%
ggplot(aes(x = row, y = value, group = ID, colour = ID))
geom_line(size = 1)
labs(x = "ID",y = "value")