[R] using dimnames as main when plotting with lapply
Uwe Ligges
ligges at statistik.tu-dortmund.de
Mon Nov 1 11:59:23 CET 2010
On 01.11.2010 11:38, Henrik Pärn wrote:
> Dear all,
>
>
>
> # 1. I use tapply to calculate various things based on a grouping variable.
>
> # simple example using the warpbreaks dataset:
> tmp <- with(warpbreaks, tapply(breaks, tension, range))
> tmp
> dimnames(tmp)
>
> # 2. I wish to plot the result of each element of tmp, using the names
> of the elements in tmp as 'main' in each plot
>
> # My attempt:
> # par(mfrow = c(3, 1)) # my preferred 'par' in this case.
> lapply(tmp, function(x) plot(x, main = dimnames(x)))
x in your anomymous function does not have any dimnames (since it it the
corresponding element of tmp. Hence go with a loop or use
lapply(seq_along(tmp), function(x) plot(tmp[[x]], main = names(tmp[x])))
Uwe Ligges
>
>
>
> Apparently not the right way to extract dimnames to main. Any suggestion
> of how to proceed?
>
> Thanks in advance for any comments.
>
> Henrik
>
>
More information about the R-help
mailing list