r - Connecting across missing values with geom_line -
i'm trying figure out if it's possible connect across missing values using geom_line. example, in link below there missing values @ time 3 in facet f. i'd line connect time 2 , 4 in case. there way achieve this?
https://farm8.staticflickr.com/7061/6964089563_b150e0c2a6.jpg

i have data frame of cumulative values so:
head(cumulative)    individual series time     value 1               x    1 -1.008821 2               x    2 -2.273712 3               x    3 -3.430610 4               x    4 -4.618860 5               x    5 -4.893075 6               x    6 -5.836532 which i'm plotting with:
ggplot(cumulative, aes(x=time,y=value, shape=series)) +      geom_point() +      geom_line(aes(linetype=series)) +      facet_wrap(~ individual, ncol=3) 
richie's answer thorough, wanted show simpler. since lines not drawn na points, approach drop these points when drawing lines. implicitly makes linear interpolation between points (as straight lines do).
using dfr richie's answer, without needing calculation of z step:
ggplot(dfr, aes(x,y)) +    geom_point() +   geom_line(data=dfr[!is.na(dfr$y),]) for matter, in case subsetting done whole thing.
ggplot(dfr[!is.na(dfr$y),], aes(x,y)) +    geom_point() +   geom_line() 
Comments
Post a Comment