I was trying to use ggplot2 to plot multiple lines in a window. this is my code here:
ggplot(type1_age, aes(x = Year, y = Value, group = Age, color = Age)) geom_line() ggtitle('The percentage distribution of type1 diabetes patients in different age groups') ylab("percentage (%)")
type1_age file looks like this: the result figure is this:
the problem is that y-axis in the result figure is not in order. can you please help me to figure out? Thanks!
CodePudding user response:
you should try this (with tidyverse):
type1_age %>%
mutate(Value = Value %>% as.character %>% as.numeric) %>%
ggplot(aes(x = Year, y = Value, group = Age, color = Age))
geom_line()
ggtitle('The percentage distribution of type1 diabetes patients in different age groups')
ylab("percentage (%)")
I suspect you Value variable to be a character vector and not a numeric one. The first part of the code should transform it in one.
Tell me if it works!