【问题标题】:Changing the colour of the regression line and data points to an XY Plot将回归线和数据点的颜色更改为 XY 图
【发布时间】:2017-01-14 14:37:37
【问题描述】:

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

我基本上已经尝试过下面的代码,但是当我将 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 图

【问题讨论】:

  • 我看到您的示例代码中有panel.points(x, y, col = 1, pch = 16)panel.loess(x,y,col=1,lwd=2)。你那里改颜色了吗? col=1 指定黑色。同样,您在此处指定 pch=16。那是您尝试 pch=19 的地方吗?
  • 感谢您回复 G5W,代码是由一位同事编写的,因此我很困惑在哪里更改代码以获得所需的结果。我听从了您的建议并更改了图形参数。答案如下:)

标签: r plot graphics regression


【解决方案1】:

答案如下:

##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 图

【讨论】:

    猜你喜欢
    • 2015-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-05
    • 2022-01-07
    • 2015-10-12
    • 2022-01-04
    • 1970-01-01
    相关资源
    最近更新 更多