Is there any function like par(new=T) for lattice. I want to plot a histogram in percentages on the right hand side and also superimpose the densityplot with its density scale on the lhs. so far I am only able to do this histogram( temp[,2]~ temp[,1],nint=100,type="desnity", xlab = "Population Size", panel = function(x, ...) { panel.histogram(x, ...) panel.densityplot(x, col = "red", plot.points=F, lwd=2) } ) If I change type="density" to type="percent" the scales for the densityplot will be too low and all I see is a horizontal line at zero (this is as expected) . However, I tried par(new=T) and nothing happens. I want to be able to put percenstages on axis 2 and density values at axis 4. Thank you Jean,
See the arguments for print.trellis, especially 'split' and 'more'. On Tue, 19 Oct 2004, Jean Eid wrote:> Is there any function like par(new=T) for lattice. I want to plot a > histogram in percentages on the right hand side and also superimpose the > densityplot with its density scale on the lhs.[...] -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
On Tuesday 19 October 2004 17:12, Jean Eid wrote:> Is there any function like par(new=T) for lattice. I want to plot a > histogram in percentages on the right hand side and also superimpose the > densityplot with its density scale on the lhs. so far I am only able to do > this > histogram( temp[,2]~ temp[,1],nint=100,type="desnity", > xlab = "Population Size", > panel = function(x, ...) { > panel.histogram(x, ...) > panel.densityplot(x, col = "red", plot.points=F, lwd=2) > } ) > > If I change type="density" to type="percent" the scales for the > densityplot will be too low and all I see is a horizontal line at zero > (this is as expected) . However, I tried par(new=T) and nothing happens. I > want to be able to put percenstages on axis 2 and density values at axis > 4.I don't think par(new=T) is what you should be looking for (and incidentally, par settings have no effect on lattice plots). It's possible to add axes after the plot (easier than it was before 2.0.0), but the design of lattice doesn't allow you to easily allocate enough space for the second set of axes. You can still do it, but it would be kludgy. Here's an example (you need to know what 'mult' should be -- it's the factor that converts the density scale to the percent scale -- it would depend on the widths of the bins and the length of x): x <- rnorm(200) mult <- 60 ## meaningless in this case histogram(x, type = "percent", panel = function(x, ...) { panel.histogram(x, ...) d <- density(x) panel.lines(d$x, mult * d$y, col = 'red') }, scales = list(y = list(tck = c(1, 0))), par.settings = list(layout.widths = list(right.padding = 5))) trellis.focus("panel", 1, 1, clip.off = TRUE) at <- pretty(c(0, 25)/mult) panel.axis(side = "right", at = mult * at, labels = at, outside = TRUE) trellis.unfocus()
> From: Jean Eid > > I figured out both questions,.. The idea is to set them with > trellis.par.set(). However, I still would like to know if there is a > tutorial for lattice package. > > Jean,Even though it's mostly about Trellis in S, the documents on http://netlib.bell-labs.com/cm/ms/departments/sia/project/trellis/, I believe, are largely applicable to lattice as well, thanks to Deepayan's hard work to keep lattice largely compatible with trellis. HTH, Andy
Maybe Matching Threads
- How to adjust y-axis when using panel.densityplot within histogram function
- side by side plot of Histogram and densityplot
- Lattice densityplot with semitransparent filled regions
- Problems drawing a colored 'rug' in the Lattice 'densityplot'
- How to generate a figure using par( ) with some densityplot( )'s