将回归线和数据点的颜色更改为 XY 图

Changing the colour of the regression line and data points to an XY Plot

这可能是一个非常基本的问题,但我正在努力更改 xyplot(下图)中的图形参数。 objective 是将回归线的颜色更改为红色,将数据点更改为蓝色。

我基本上尝试了下面的代码,但是当我将 pch=19col="blue" 添加到代码颜色不变。

如果有人能提供帮助,我将不胜感激。

XY 图的 R 代码

    ##Create a vector

    Z3 <- as.vector(as.matrix(Pairs[, c("Lighting",
                                        "Distance_Coast",
                                        "Temp_Canopy",
                                        "Temp_Open",
                                        "T.max.open",
                                        "T.min.open",
                                        "T.min.canopy",
                                        "T.max.canopy")]))


  #Setup the data in vector format for the xyplot

   Y10 <- rep(Pairs$Canopy_index, 8)

   MyNames <-names(Pairs[,c("Lighting",
                            "Distance_Coast",
                            "Temp_Canopy",
                            "Temp_Open",
                            "T.max.open",
                            "T.min.open",
                            "T.min.canopy",
                            "T.max.canopy")])

   ID10 <- rep(MyNames, each = length(Pairs$Canopy_index))

   ID11 <- factor(ID10, labels = c("Lighting",
                                   "Distance_Coast",
                                   "Temp_Canopy",
                                   "Temp_Open",
                                   "T.max.open",
                                   "T.min.open",
                                   "T.min.canopy",
                                   "T.max.canopy"),
                        levels = c("Lighting",
                                   "Distance_Coast",
                                   "Temp_Canopy",
                                   "Temp_Open",
                                   "T.max.open",
                                   "T.min.open",
                                   "T.min.canopy",
                                   "T.max.canopy"))
      ##XY Plot

      xyplot(Y10 ~ Z3 | ID11, col = 1,
      strip = function(bg='white',...) strip.default(bg='white',...),
      scales = list(alternating = T,
      x = list(relation = "free"),
      y = list(relation = "same")),
      xlab = "Explanatory Variables",
      par.strip.text = list(cex = 0.8),
      ylab = "Canopy Index",
      panel=function(x, y, subscripts,...){
      panel.grid(h =- 1, v = 2)
      panel.points(x, y, col = 1, pch = 16)
      if(ID10[subscripts][1] != "Minutes.After.Sunset") {panel.loess(x,y,col=1,lwd=2)}
   })

XY 图

答案如下:

##XY Plot
  xyplot(Y10 ~ Z3 | ID11, col = 1,
         strip = function(bg='white',...) strip.default(bg='white',...),
         scales = list(alternating = T,
                 x = list(relation = "free"),
                 y = list(relation = "same")),
                 xlab = "Explanatory Variables",
                 par.strip.text = list(cex = 0.8),
                 ylab = "Canopy Index",
                 panel=function(x, y, subscripts,...){
                 panel.grid(h =- 1, v = 2)
                 panel.points(x, y, col = "blue", pch = 19)
                 if(ID10[subscripts][1] != "Minutes.After.Sunset"){panel.loess(x, y, col="red", lwd=2)}
                 })

XY 图