2

I want to plot two quantitative variables, in panels determined by a third factor variable, in R using lattice::xyplot(). I want transparent black symbols, with solid red trend lines. To provide a working example, I'll use the iris dataset in R. None of the four attempts below achieve the desired outcome (one of which was informed by the thread at Add alpha value to lattice xyplot panel function):

library(datasets)
data(iris)

xyplot(Sepal.Length ~ Sepal.Width | Species, data = iris,
   type = c("p","smooth"), alpha=.1, pch=19, col="black", col.line="red", lwd=2)

xyplot(Sepal.Length ~ Sepal.Width | Species, data = iris,
   type = c("p","smooth"), 
   par.settings = list(superpose.symbol = list(cex=1, pch=20, col="black", alpha = 0.1),
                       superpose.line = list(col = "red", lwd = 2)))

xyplot(Sepal.Length ~ Sepal.Width | Species, data = iris, 
   grid = TRUE, scales=list(tck=c(1,0), x=list(cex=1.1), y=list(cex=1.1)),
   par.settings = list(superpose.symbol = list(pch =20, cex = 1, col = c("#0808084d"))),
   type = c("p", "smooth"), col.line =c("red"),lwd = 2)

xyplot(Sepal.Length ~ Sepal.Width | Species, data = iris,
   par.strip.text=list(cex=0.6),
   type = c("p","smooth"), 
   par.settings = list(superpose.symbol = list(cex=1, pch=20, col="black", alpha = 0.1),
                       superpose.line = list(col = "red", lwd = 2)))

Any guidance is much appreciated.

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
gcgaines
  • 43
  • 5

1 Answers1

3

How about

trans_black <- adjustcolor("black",alpha.f=0.2)
xyplot(Sepal.Length ~ Sepal.Width | Species, data = iris,
       type = c("p","smooth"), pch=19, col=trans_black,
       col.line="red", lwd=2)

?

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453