[R] Lattice: type="p" stopped working in panel.average
Alexandr Malusek
alexandr.malusek at gmail.com
Tue Oct 19 16:28:48 CEST 2010
Dear Deepayan,
I had to swap "x" and "y" (see below), but otherwise it worked
perfectly. Thank you for your help.
mypanel.average <- function(x, y, FUN = mean, ...)
{
aa <- aggregate(x ~ as.numeric(y), data = environment(), FUN = FUN)
panel.points(aa[[2]], aa[[1]], ...)
}
plot <- bwplot(year ~ Eann, data=df, horizontal = T,
xlab = "E / mSv",
ylab = "year",
box.ratio = 1.5,
panel=function(...) {
panel.grid(h=0, v=-1)
mypanel.average(FUN=max, pch=3, col="black", ...)
panel.violin(adjust=0.3, kernel="gaussian", ...)
mypanel.average(FUN=min, pch=3, col="black", ...)
mypanel.average(FUN=mean, pch=20, col="black", ...)
mypanel.average(FUN=median, pch=0, col="black", ...)
}
)
Regards,
Alexandr
On Tue, Oct 19, 2010 at 1:52 PM, Deepayan Sarkar
<deepayan.sarkar at gmail.com> wrote:
> On Tue, Oct 19, 2010 at 4:18 PM, Alexandr Malusek
> <alexandr.malusek at gmail.com> wrote:
>> Hi,
>>
>> The behavior of panel.average has changed. In March 2010, I plotted
>> the attached r_plotViolinOfAnnualE_old.eps. (I don't know the version
>> of R). Today, I plotted the attached r_plotViolinOfAnnualE_new.eps
>> using R version 2.12.0 (2010-10-15). Both figures were produced via
>> the same script:
>>
>> ...
>> plot <- bwplot(year ~ Eann, data=df, horizontal = T,
>> xlab = "E / mSv",
>> ylab = "year",
>> box.ratio = 1.5,
>> panel=function(...) {
>> panel.grid(h=0, v=-1)
>> panel.average(fun=max, type="p", pch=3, col="black", ...)
>> panel.violin(adjust=0.3, kernel="gaussian", ...)
>> panel.average(fun=min, type="p", pch=3, col="black", ...)
>> panel.average(fun=mean, type="p", pch=20, col="black", ...)
>> panel.average(fun=median, type="p", pch=0, col="black", ...)
>> }
>> )
>> ...
>>
>> The old version of R plotted points as defined by type="p", the new
>> version plotted lines. I don't know whether it is a bug or a new
>> feature. Anyway, is there an easy way of getting the old result with
>> the new version of R?
>
> The change happened in Dec 2009, probably to prevent unintended
> capturing of 'type' (panel.average is an alias for panel.linejoin,
> which indicates that the original intention was to draw lines).
>
> In hindsight, this was probably not the best choice. However, you can
> get the same effect fairly easily with
>
> mypanel.average <- function(x, y, FUN = mean, ...)
> {
> panel.points(aggregate(as.numeric(y) ~ x, data = environment(), FUN
> = FUN), ...)
> }
>
> -Deepayan
>
More information about the R-help
mailing list