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?
D Kelly O'Day
http://chartsgraphs.worpress.com http://chartsgraphs.wordprss.com
--
View this message in context:
http://r.789695.n4.nabble.com/Unexpected-Gap-in-simple-line-plot-tp3228853p3228853.html
Sent from the R help mailing list archive at Nabble.com.
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
You do have missing values. Setting xlim does not subset the data.
How about
########
link <- "http://processtrends.com/files/RClimate_CTS_latest.csv"
cts <- read.csv(link, header = TRUE)
scts <- subset(cts, !is.na(GISS) & !is.na(cts)) ## remove defectives
plot(GISS ~ yr_frac, scts, type = "l", xlim = c(1982, 1983),
xaxs = "i", yaxs = "i")
points(GISS ~ yr_frac, scts, type = "p", col = "red")
########
?
Bill Venables
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
On Behalf Of D Kelly O'Day
Sent: Friday, 21 January 2011 11:12 AM
To: r-help at r-project.org
Subject: [R] Unexpected Gap in simple line plot
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?
D Kelly O'Day
http://chartsgraphs.worpress.com http://chartsgraphs.wordprss.com
--
View this message in context:
http://r.789695.n4.nabble.com/Unexpected-Gap-in-simple-line-plot-tp3228853p3228853.html
Sent from the R help mailing list archive at Nabble.com.
______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.