leeper/slopegraph

Handle missing data points better

bshor opened this issue · 3 comments

bshor commented

Great package! But I'm still having difficulty with missing values. I'm attaching some data on state polarization for the northeast. Everything's there except the 2014 value for MA. This messes up the plot. I'd like to have the 2008 point for MA go directly to 2014. But as it is, MA gets orphaned after 2008, and the point for 2017 (the end) is not connected to anything.

na.span should do the job but it doesn't.

This is the code I use:

rownames(sg)=sg$st; sg$st=NULL
colnames(sg)=str_c("Year.",colnames(sg))
    
slopegraph(sg, col.line='gray',col.lab = 'black', decimals=1,
     xlabels=c('1996','2000','2004','2008','2014','2017'), 
     cex.lab = 1, cex.num=0.75)

ne polarization slopegraph
slopegraph problem 042117.zip

Hi,

So let's assume that MA was missing in 2008 as you mentioned and that RI was missing in 2004 (it's less subtle and easy to see). You want this straight line interpolation to happen correct?

bbb

bshor commented

Thanks for taking this up!

I think the correct display should be not to impute a point (eg to display the numeric value) but rather to just draw the line from the last non-missing data value to the next non-missing data value.

For MA it should be a line from 2008 to 2017 with no numeric value present for 2014 (where there is missing data).

Yes that's what it is doing in the example I gave you above. It's just difficult to see that because MA and NJ are so close together at that point. It's easier to see in the RI example where I made 2004 = NA