Solved!
Thank you @Gregor and @eipi10. I solved this problem by
Converting the dataframe to
long
format:
dat.long <-poverty %>% gather(key, value, -Year)
Filter out all the
NA
s:
dat.long<-dat.long[complete.cases(dat.long), ]
ggplot!
Preface
Unlike other questions, I have a quite odd data frame with several NA
values:
When I geom_line
them:
ggplot(poverty, aes(Year))+
geom_line(aes(y = poverty$Poverty..BM.2002.....of.world.population., colour = "2002 Poverty"))+
geom_line(aes(y = poverty$Extreme.Poverty..BM.2002.....of.world.population., colour = "2002 Extreme Poverty")) +
geom_line(aes(y = poverty$Less.than.1.90..per.day..World.Bank..2015......of.world.population., colour = "2015 Poverty"))
I get discontinued lines:
There are SO posts suggesting plot points first, then connect them by group
. I thought it is a good idea when I got something like this:
Problem
How do I connect the dots? (note, I don't have factor
class column in my dataframe, so I can't really do it by group=
)
Desired output:
Side Request
How do I change the legend title?
Thank you!