[R] color of error bars in Dotplot (Hmisc)
Peter Ehlers
ehlers at ucalgary.ca
Wed Jul 27 18:56:46 CEST 2011
On 2011-07-27 05:35, Dieter Menne wrote:
>
> Irene Prix wrote:
>>
>>
>> In a grouped Dotplot, is there any way to set the color of error bars to
>> be the same as the corresponding symbols?
>> ...
>> require(lattice)
>> require(Hmisc)
>> data(barley)
>>
>> Dotplot(variety~Cbind(yield, yield+2, yield-2)|year, groups=site,
>> data=barley)
>>
>>
>
> Customizations of this type can require tricky-digging into the code.
> Dotplot calls panel.dotplot, where you find a line
>
> plot.line<- trellis.par.get(if (gp) "superpose.line" else "plot.line")
>
> gp=TRUE when there are groups. So let's give it a try (thanks for the
> self-contained example code)
>
> # using global assignment here, better use local
> superpose.line = trellis.par.get("superpose.line")
> superpose.line
> superpose.line$col=c("black","green","red")
> superpose.line$lwd=3
> trellis.par.set("superpose.line",superpose.line)
>
> Dotplot(variety~Cbind(yield, yield+2, yield-2)|year, groups=site,
> data=barley)
> ----
>
> The good news: the lines are black. The bad news: they are all black, which
> is the first term. So it looks like these lines are not vectorized (Frank,
> correct me....)
The code for panel.Dotplot contains these two lines:
segmnts(other[,1], y, other[,nc], y, lwd=plot.line$lwd[1],
lty=plot.line$lty[1], col=plot.line$col[1])
If you replace the second line with
lty=plot.line$lty[1], col=plot.line$col)
then superpose.line can take a vector of colours. But you
have to be careful to match the colour sequence to that used
in the plot symbol. I don't think that this will have any
adverse effect except possibly in any key() assignments.
Here's an example:
Dotplot(variety ~ Cbind(yield, yield+2, yield-2)|year,
groups = site, data = barley, pch = 16, col = 1:6,
par.settings = list(
superpose.line = list(
col = as.numeric(barley$site), lwd = 2)),
panel = mypanel.Dotplot)
where mypanel.Dotplot() is panel.Dotplot() with the modified
line as indicated above.
Peter Ehlers
>
> You might be able to get customized results with panel.arrow.
>
> Dieter
>
>
>
>
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/color-of-error-bars-in-Dotplot-Hmisc-tp3697678p3698327.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list