color of error bars in Dotplot (Hmisc)

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

color of error bars in Dotplot (Hmisc)

Irene Prix
Hello!

In a grouped Dotplot, is there any way to set the color of error bars
to be the same as the corresponding symbols?


Example data:

require(lattice)
require(Hmisc)
data(barley)

Dotplot(variety~Cbind(yield, yield+2, yield-2)|year, groups=site,
data=barley)


I experimented with changing trellis settings of plot.line (as
mentioned in the Hmisc documentation) as well as col.line settings in
"simpleTheme", but that didn't work. Changing the error bars to any
one other color does work, but I can't seem to figure out how to set
them to the color of each group-specific symbol...

I'd be grateful for any advice,

Irene

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: color of error bars in Dotplot (Hmisc)

Dieter Menne
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....)

You might be able to get customized results with panel.arrow.

Dieter





Reply | Threaded
Open this post in threaded view
|

Re: color of error bars in Dotplot (Hmisc)

Peter Ehlers
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.
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.