[R] densityplot and histogram

Jean Eid jeaneid at chass.utoronto.ca
Thu Oct 21 16:15:15 CEST 2004


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,

On Thu, 21 Oct 2004, Jean Eid wrote:

> Deepayan,
>
> Thank you so much,... works like a charm. However, I have two more
> questions:
>
> a) in ?panel.axis is says
> ...: certain graphical parameters (fonts, color, etc) can be
>           supplied. See the formal argument list for valid names.
> I tried to change your example to have to have
> 	panel.axis(side = "right",
> 	           at = mult * at, labels = at,
>         	   outside = TRUE, tck=-.5, font=2)
>
> However, it does output an error:
> 	Error in panel.axis(side = "right", at = mult * at, labels = at, outside = TRUE,  :
> 	unused argument(s) (font ...)
>
> When you say "See the formal argument for valid names" where do I see
> these, and is there a pdf tutorial on the lattice package that I can take
> a look at.
>
>
> b) How do I change the xlab and yalb to bold fonts.
>
>
>
> Thank you so much for all the help,
>
>
> Jean,
>
>
> On Wed, 20 Oct 2004, Deepayan Sarkar wrote:
>
> > 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()
> >
> >
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>




More information about the R-help mailing list