0

I am trying to create an xyplot with the key on the right hand side and symbols as well as lines (which have to be given in the key as well). I'm running the following code:

xyplot(value ~ variable | conditionCol1 + conditionCol2,
              data = rt, groups = groupingCol, type = "o", pch = 1:6,
              auto.key = list(space = "right", pch = 1:6),
              xlab = "Instance Size",
              ylab = "Execution Time")

The returned graph is correct and has both lines and different symbols for the different groups, however all symbols in the key are coming up as circles...

Tania
  • 285
  • 1
  • 4
  • 13

1 Answers1

4

Instead of passing pch as its own argument, pass it as a component of the par.settings argument. That should ensure that the graph and the key use the same parameters.

The trick is determining which component of par.settings to use. In this case, it would be superpose.symbol, since panel.superpose is the panel function used when you use the group argument, and you want to change the symbol that is plotted. So:

xyplot(value ~ variable | conditionCol1 + conditionCol2,
              data = rt, groups = groupingCol, type = "o",
              par.settings = list(superpose.symbol = list(pch = 1:6)),
              auto.key = list(space = "right"),
              xlab = "Instance Size",
              ylab = "Execution Time")

And using a reproducible dataset:

library(ggplot2)
xyplot(cty ~ hwy | cyl + fl,
              data = mpg, groups = year, type = "o",
              par.settings = list(superpose.symbol = list(pch = 1:6)),
              auto.key = list(space = "right"),
              xlab = "Instance Size",
              ylab = "Execution Time")
BenBarnes
  • 19,114
  • 6
  • 56
  • 74