[R] finding the plot limits generated by default
Marc Schwartz
marc_schwartz at me.com
Fri May 14 18:33:51 CEST 2010
Justin,
Try something like this:
par(mfrow = c(2, 1))
drawGffPlots2(data1, data2, trackingDye = TRUE,
slice = "chr13", newDev = 0)
plot(densities_subset$V4, densities_subset$V6, type = "h",
xlim = par("usr")[1:2],
xaxs = "i",
xlab = "Position", ylab = "Gene Density")
Using 'xaxs = "i"' in the second call to plot() should fix the x axis range at the exact values passed for 'xlim'.
HTH,
Marc
On May 14, 2010, at 11:09 AM, Justin Fincher wrote:
> Thank you for your reply, but I have additional questions. I agree that getting the common ranges before plotting would be the best scenario, it is just complicated by the fact that the first plot is generated with a function where all the data is passed in and within the function the data is subset and plotted so I don't have control over the parameters of the plot. That is why I am trying to just make the second plot (the one I have complete control over) match up. I tried the par("usr") but am having an odd result. Below is from my R console.
>
> > par(mfrow=c(2,1))
> > drawGffPlots2(data1,data2,trackingDye=TRUE,slice="chr13",newDev=0)
> NULL
> > par("usr")[1]
> [1] 14215173
> > plot(densities_subset$V4,densities_subset$V6,type="h",xlim=c(par("usr")[1],par("usr")[2]),xlab="Position",ylab="Gene Density")
> > par("usr")[1]
> [1] 10062761
>
> This creates two rows, runs the function which populates the first row, then I check the parameter you suggested so that I may use it for the second plot. I then pass it to plot(), but the axes still don't line up so I check the same parameter after the second plot has been drawn and it is very different. Should par("usr")[1] not be exactly the same the second time I display it as I passed it as the minimum for the second plot? Any help would be appreciated.
>
> - Fincher
>
>
> On Fri, May 14, 2010 at 11:45, Marc Schwartz <marc_schwartz at me.com> wrote:
> On May 14, 2010, at 9:59 AM, Justin Fincher wrote:
>
> > I have two datasets that I would like to plot in a single figure. The first
> > plot is generated by a function that then takes a subset of the data. (It
> > is biological data so it is usually by chromosome e.g.
> > function(data1,subset="chr8") ) Since not only are the chromosomes different
> > sizes, but across different datasets there may be different numbers of
> > points for a single chromosome, I do not know the coordinates on the x-axis
> > prior to running the function.
> >
> > I want the scale of the second plot to align to that of the first, but I
> > don't know how to find the default xlim for the graph generated by the
> > function. Is there any way to access this information so I can then pass it
> > to the plot() of the second plot? Thanks!
> >
> > - Fincher
>
>
> The result of par("usr") will give you the actual limits of the x and y axes (plot region) once the first graphic is drawn to the device. See ?par for more information. Note that by default, R will extend the data ranges by 4% (see 'xaxs' in ?par).
>
> However, you are better off getting the common ?range of the relevant values in both subsets of data before plotting and then explicitly set the same x and y axis ranges in each plot by using the 'xlim' and 'ylim' arguments to plot().
>
> HTH,
>
> Marc Schwartz
>
>
>
> --
> This message has been scanned for viruses and
> dangerous content by MailScanner, and is
> believed to be clean.
>
>
More information about the R-help
mailing list