[R] Setting the colors of lines in a trellis plot...

Deepayan Sarkar deepayan.sarkar at gmail.com
Mon Jul 10 20:27:49 CEST 2006


On 7/10/06, Jamieson Cobleigh <cobleigh at gmail.com> wrote:
> With some help from those with expertise on this list, I managed to
> produce a plot using trellis that looked like I wanted it to look.
> Now, I need to take the same plot and make the lines on it color, but
> I want to specify the color for the lines myself.
>
> I've managed to make the key use the colors I want.  I've managed to
> make the symbols of the actual plot use the colors I want.  But I have
> been unable to find the correct incantation to make the lines of the
> actual plot use the colors I want.  Here's the relevant section of
> code:
>
>   mycolors <- c("black", "darkgreen", "red")
>
>   mylines   <- Rows(superpose.line, 1:numlines);
>   mylines$col <- mycolors
>
>   mysymbols <- Rows(superpose.symbol, 1:numlines);
>   mysymbols$pch <- c(15:18)[1:numlines]
>   mysymbols$col <- mycolors
>
>   print(xyplot(
>     panel = panel.superpose,
>     log10(states) ~ size,
>     groups=category,
>     data=data,
>     type='b',
>     lwd = 2,
>     par.settings = list(superpose.symbol=mysymbols),

You have forgotten to add 'superpose.line=mylines'.

>     ylim=c(y_min, y_max),
>     scales = list(tck=c(1, 0), axs="r",
>
>                   x=list(tick.number=(xmax - xmin + 1), at=xmin:xmax,
>                   labels=xmin:xmax, cex=1.75),
>
>                   y=list(axs="r", rot=c(90, 0), labels=y_labels,
>                          at=y_at, cex=1.75
>                   )
>               ),
>     key = list (
>       text  = list(levels(data$category)),
>       lines = list(type="b",
>                    lty=mylines$lty,
>                    pch=mysymbols$pch,
>                    cex=rep(1.25, numlines),
>                    col=mylines$col),

You might consider using the 'auto.key' argument instead of 'key' (YMMV).

-Deepayan

>       x = .98,
>       y = .25,
>       corner=c(1,0)
>     ),
>     xlab = list(label="System Size", cex=2),
>     ylab = list(label="States", cex=2),
>   ))
>
>
> Can anyone help me out with this?
>
> Thanks!
>
> Jamie



More information about the R-help mailing list