so I'm trying to Plot chart
. I filtered the original dataset Datengf
to get the median income of each year ( MULTYEAR
) and the variable Schulbildung
. No chart looks like this: chart . Now I want to plot chart
by using ggplot
and geom_line
. On the x-axis MULTYEAR
and on the y-axis the medianincome
. But I want it to be a different line and color for each value of Schulbildung
.
Chart code:
chart <- Datengf %>%
filter(SEX == 1)%>%
group_by(MULTYEAR,Schulbildung) %>%
summarise(medianincome = median(INCWAGE))%>%
ungroup()%>%
mutate(Schulbildung = ifelse(Schulbildung < 12, "others", Schulbildung)) %>%
group_by(Schulbildung,MULTYEAR)%>%
summarise(medianincome = sum(medianincome))
I tried using
chartplot <- chart %>%
ggplot(aes(x = MULTYEAR, y = medianincome))+
geom_line()
but the chart is an complete mess.
Specify color
in the aes
function:
chartplot <- chart %>%
ggplot(aes(x = MULTYEAR, y = medianincome, color = Schulbildung))+
geom_line()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.