Use the `xlim` parameter of the `plot` function.

IFor example, if X1 and X2 are the variables that contain the values of your
x-axis,
do xlim1 <- range(X1,X2),
than do plot(........, xlim = xlim1,...)

Hope this helps.


2011/6/15 bjmjarrett <bjmjarrett@gmail.com>

> Hi all,
>
> I have scoured the archives of this forum but nothing quite seems to fit
> the
> bill...
>
> I would like to plot a graph displaying two variables (y axes) that share
> date as the x axis. However, the date values for each variable are not the
> same - for example, some parasitoids were not released on days that
> collections from the trap took place, whilst sometimes releases did occur
> on
> the same day. I would like to align them. My code is:
>
> ####
> CollectionDate<-as.Date(CollectionDate,"%m/%d/%Y") # days that had
> collections
> release.date.Total<-as.Date(release.date.Total,"%m/%d/%Y") # days that had
> releases
>
> par(mar=c(5,4,4,4)+0.1)
>
>
> plot(CollectionDate[data$Trap=="DPAU1"],TotalP[data$Trap=="DPAU1"],type="n",ylim=c(0,80),xlab="Time",ylab="Number
> of egg masses") # I am using one trap of many
>
> lines(CollectionDate[data$Trap=="DPAU1"],TotalP[data$Trap=="DPAU1"],lwd=2)
>
> par(new=T)
>
>
> plot(release.date.Total[data$Trap=="DPAU1"],parasitoid.total[data$Trap=="DPAU1"],axes=F,type="h",lty=1,col="red",xlab="",ylab="",lwd=1.2)
>
> axis(4,las=1)
>
> mtext(side=4,line=3,"Total parasitoids released")
> ###
>
> As in the above code, I suppressed the axes for the second plot, but if I
> don't the x axis (date) has two tick marks for each year.
>
> Is there a way to align the date objects to begin with without compromising
> the graphs themselves?
>
> Thanks in advance,
>
> Ben
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/plot-with-two-y-axes-BUT-unaligned-x-axis-tp3599162p3599162.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help@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.
>

	[[alternative HTML version deleted]]

