1

I am plotting in xyplot() as per below. I put symbols on the plot with print(panel.points()) and it works. But I need to save the plot with the points to a variable (a in the example) so I can use grid arrange to combine it with other plots in the same picture. Ideas?

dev.off()
x <- c(1:10)
y <- c(1:10)

a <- xyplot(y ~ x, type = "l")

trellis.focus("panel", 1, 1, highlight = FALSE) 

print(panel.points(x[c(5,10)], 
               y[c(5,10)], 
               pch = 19, 
               cex = 0.75, 
               col = c("red", "black")))
user3504322
  • 545
  • 2
  • 5
  • 18
  • https://stackoverflow.com/questions/31128235/how-to-add-new-dots-to-existing-lattice-plot-in-r might be useful – user20650 Sep 22 '17 at 22:32

1 Answers1

1

Use panel.points within a panel function that calls panel.xyplot to do the main plot:

b = xyplot(
      y~x,type="l",
      panel=function(...){
       panel.xyplot(...)
       panel.points(
        x[c(5,10)],y[c(5,10)],
        cex=0.75, col=c("red","black"),pch=19
       )
       }
    )
Spacedman
  • 92,590
  • 12
  • 140
  • 224