r - Linetypes missing for one group ggplot2 -
i have following data:
date, name, bin,group, value 2017-08-19,a1,0,1,302 2017-08-19,a3,0,1,35 2017-08-19,a4,0,1,33 2017-08-19,a6,0,1,43 2017-08-19,p1,0,0,76 2017-08-19,i3,0,0,23 2017-08-19,cl,1,1,73 2017-08-19,c,1,0,2 2017-09-19,a1,0,1,302 2017-09-19,a3,0,1,35 2017-09-19,a4,0,1,33 2017-09-19,a6,0,1,43 2017-09-19,p1,0,1,76 2017-09-19,i3,0,1,23 2017-09-19,cl,1,1,73 2017-09-19,c,1,1,2 for reason ending plot not show linetype 1 of groups.
here code:
p <- df %>% ggplot(aes(y=value,x=date,color=name))+ geom_point(aes(shape=factor(bin)))+ geom_line(aes(linetype=factor(group)))+ geom_hline(aes(yintercept = 0))+ theme_minimal() p you can see image below 1 of linetypes not showing.
how other linetype show?
the reason lines aren't showing name's there 2 group's. result, ggplot doesn't ones pick showing lines , apparently decides plot nothing @ all.
a possible solution change group-value first 1 of each name , plot:
df %>% group_by(name) %>% mutate(group = first(group)) %>% ggplot(aes(x = date, y = value, color = name)) + geom_point(aes(shape = factor(bin))) + geom_line(aes(linetype = factor(group))) + geom_hline(aes(yintercept = 0)) + theme_minimal() which gives following plot:


Comments
Post a Comment