[R] barplot: invalid 'xlim' value
Joshua Wiley
jwiley.psych at gmail.com
Sun May 16 00:03:40 CEST 2010
Eric,
I was thinking about it more and if you have all the data in your
example read in, look at this:
####################
plot(ttime.80.2,well.80.2$Reading,type="l",col="blue",lwd=2)
par("usr")
barplot(coldat,horiz=TRUE,axes=FALSE,col=8,space=0)
par("usr")
barplot(coldat,horiz=TRUE,axes=FALSE,ylim=ylim,col=8,space=0) #even
this does not work because the data from coldat is outside the bounds
of the coordinates given by ylim
####################
from ?par
'usr' A vector of the form 'c(x1, x2, y1, y2)' giving the extremes
of the user coordinates of the plotting region.
even if you just add ylim in, which is numeric in your example, you
are setting plotting coordinates that are outside the bounds of the
data you have to plot in coldat. Here is your first plot again, with
the purple points, and large red points created using a numeric
approximation xlim.
####################
plot(ttime.80.2,well.80.2$Reading,type="l",col="blue",lwd=2)
well80.2.weeklyMean<-rollmean(well.80.2$Reading,168)
points(ttime.80.2[seq(84,756,by=1)],well80.2.weeklyMean,col="red",type="l",lwd=2)
week.vline<-seq(ttime.80.2[1],as.POSIXlt("2000-07-31 02:00:00"),by="week")
abline(v=week.vline,col="grey60")
ylim<-c(floor(min(well.80.2$Reading)),ceiling(max(well.80.2$Reading)))
xlim<-c(as.POSIXlt(ttime.80.2[1],"%Y-%m-%d
%H:%M",tz=""),as.POSIXlt(ttime.80.2[length(ttime.80.2)],"%Y-%m-%d
%H:%M",tz=""))
points(xlim,ylim,col="purple",pch=19,type="p")
##numeric approximation of the purple points
points(x=c(as.numeric(as.Date(xlim[1]))*24*60*60,
as.numeric(as.Date(xlim[2]))*24*60*60), y=ylim, col="red", cex=3)
####################
I still don't really have any ideas for a solution. It seems like you
could do some rescaling, but there is probably a more elegant way if
one knew how to work with date/time data better.
Josh
On Sat, May 15, 2010 at 12:12 PM, emorway <emorway at engr.colostate.edu> wrote:
>
> Josh,
>
> Thanks for looking into this further. Picking up on your hint I tried to
> coerce the xlim values as well:
>
> barplot(coldat,horiz=TRUE,axes=FALSE,xlim=c(as.numeric(strptime(well.80.2$date[1],"%m/%d/%Y
> %H:%M")),as.numeric(strptime(well.80.2$date[length(well.80.2$date)],"%m/%d/%Y
> %H:%M"))),ylim=ylim,col=8,space=0)
>
> It doesn't complain at this point, but it doesn't appear to do anything
> either. Hopefully someone else will spot the problem.
>
> Eric
> --
> View this message in context: http://r.789695.n4.nabble.com/barplot-invalid-xlim-value-tp2217919p2218029.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.
>
--
Joshua Wiley
Senior in Psychology
University of California, Riverside
http://www.joshuawiley.com/
More information about the R-help
mailing list