Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

override R lattice parallelplot auto.key legend colors

Tags:

r

lattice

I used the lattice package parallelplot method to plot data and ran into trouble generating the legend. I created a vector of custom colors for the plot, but couldn't find a way to pass them in to override the default colors shown in the legend. Although I ran out of time and ended up correcting the legend colors in Photoshop, I'd like to learn the correct way to do this in lattice.

Here is the code that generated the plot with a 4 column legend:

parallelplot(acc, horizontal.axis=FALSE, col=acc_colors, lwd=1.5, cex=2.5, 
    ylab="Accuracy (Min = 50%, Max = 100%)", 
    xlab="Activity (overall = average across activities)", 
    main="Human Activity Recognition Accuracy", 
    scales=list(cex=1), 
    auto.key=list(text=c("Test Set", "Test Subject", "Training Set", "Training Subject"), 
    title=" ", 
    space="top", columns=4, points=FALSE) 
)

Any ideas how to pass in custom legend colors?

like image 568
softweave Avatar asked Mar 16 '13 17:03

softweave


1 Answers

Use of show.settings() and str(trellis.par.get()) showed the graphic parameter that needed to be customized was superpose.line. Using par.settings to pass in customized settings gave custom key colors and line widths while still using auto.key:

acc_par <- list(superpose.line = list(col = key_colors), lwd=1.5, lty=1.5)
parallelplot(acc, horizontal.axis=FALSE, col=acc_colors, lwd=1.5, cex=2.5, 
           ylab="Accuracy (Min = 50%, Max = 100%)",
           xlab="Activity (overall = average across activities)", 
           main="Human Activity Recognition Accuracy",
           scales=list(cex=1),
           par.settings=acc_par,
           auto.key=list(text=c("Test Set", "Test Subject", "Training Set", "Training Subject"),
                         title=" ", space="top", columns=4, lines=TRUE)
           )
}

This article was helpful to finding this solution.

like image 141
softweave Avatar answered Sep 24 '22 01:09

softweave