Geo-sp
Geo-sp

Reputation: 1704

How to control ellipse colors in lattice xyplot?

I want to change ellipse colors and width within lattice xyplot. Here is an example:

library(lattice)
xyplot(Sepal.Length ~ Petal.Length, groups=Species,
       data = iris, scales = "free",
       par.settings = list(superpose.symbol = list(pch = 18, cex = 0.9,col = c("green", "orange","brown"),superpose.line = list(lwd=2))),
       panel = function(x, y, ...) {
           panel.xyplot(x, y, ...)
           panel.ellipse(x, y, ...)
       },
       auto.key = list(x = .1, y = .8, corner = c(0, 0)))

I want to match ellipse colors with the points and increase their width. enter image description here

Upvotes: 1

Views: 413

Answers (1)

nathanesau
nathanesau

Reputation: 1721

As mentioned in the comment by user20650 you can add additional options to the panel.ellipse function. In this case, you want to add the col and lwd options.

library(lattice)
library(latticeExtra) # you forgot to mention this package in question

xyplot(Sepal.Length ~ Petal.Length, groups = Species, data = iris,
       scales = "free", auto.key = list(x = 0.1, y = 0.8, corner = c(0, 0)),
       par.settings = list(superpose.symbol = list(pch = 18, cex = 0.9,
                           col = c("green", "orange","brown"),
                           superpose.line = list(lwd=2))),
       panel = function(x, y, ...) {
           panel.xyplot(x, y, ...)
           panel.ellipse(x, y, col = c("green", "orange", "brown"), 
                         lwd = c(5, 5, 5), ...)
       }
)

enter image description here

Upvotes: 2

Related Questions