[R] Unexpected Gap in simple line plot

Duncan Murdoch murdoch.duncan at gmail.com
Fri Jan 21 02:26:28 CET 2011


On 20/01/2011 8:12 PM, D Kelly O'Day wrote:
>
> I am getting an unexpected gap in a simple plot of monthly data series.
>
> I have created a csv file of monthly climate observations that I store
> on-line. When I download the csv file and plot one of the series, I get a
> gap even though there is data for the missing point.
>
> Here is a snippet to show the problem.
>
>    ## Strange plot results
>      link<- "http://processtrends.com/files/RClimate_CTS_latest.csv"
>      cts<- read.csv(link, header=T)
>
>      ## Simple line plot - gap for no reason
>      plot(cts$yr_frac, cts$GISS, type="l", xlim=c(1982, 1983),xaxs="i",
> yaxs="i")
>
>     ## May, 1982 observation missing
>     ## Add points to plot in red, to see if May shows up
>     points(cts$yr_frac, cts$GISS, type="p", col="red")
>     ## yes, May shows up in points
>
> ## Look at cts data.frame. No obvious problems to me??
>    small<- subset(cts, cts$yr_frac>1982&  cts$yr_frac<1983)
>    small[,c(1,3)]
>
> The same problem occurs in the other data vectors (HAD, NOAA, RSS, UAH, etc)
>
> I have not been able to figure why I am getting the gap and how to show a
> continuous line through May, 1982 data points.
>
> Any suggestions?

Look at the data, not a subset of the data.  Printing cts, I see the 
following:

1226 1982.12 198202  0.07 -0.033  0.0801 -0.099 -0.201  0.1219  0.674 -0.052
1227 1982.21 198203 -0.12 -0.123  0.0265 -0.167 -0.347  0.1262  0.503 -0.052
1228    4.00     NA    NA     NA      NA     NA     NA      NA     NA     NA
1229 1982.29 198204 -0.03  0.024  0.1508 -0.116 -0.236  0.1311  0.495 -0.150
1230    5.00     NA    NA     NA      NA     NA     NA      NA     NA     NA
1231 1982.38 198205  0.10  0.041  0.1268 -0.228 -0.236  0.1730  0.876 -0.168

You get a better view in the data editor, seen by edit(cts) (on Windows, 
but I think it works on other systems too...)

There are a couple of weird records with NA values around the gap.  NA 
in a line plot causes a gap in the line.

Duncan Murdoch



More information about the R-help mailing list