2017-01-14 21 views
0

這可能是一個非常基本的問題,但我正在努力改變xyplot(下圖)中的圖形參數。目標是將回歸線的顏色更改爲紅色,將數據點更改爲藍色。將回歸線和數據點的顏色更改爲XY圖

我已經試過basicaly下面的代碼,但是當我添加PCH = 19,並山坳=「藍色」到代碼的顏色沒有改變。

如果有人能幫忙,我會非常感激。爲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圖

enter image description here

+1

我看到你有'panel.points(X,Y,COL = 1,PCH = 16)'和 'panel.loess(X,Y,COL = 1,lwd = 2)'在你的示例代碼中。你有沒有改變顏色? col = 1指定黑色。同樣,你在那裏指定pch = 16。那是你試過pch = 19的地方嗎? – G5W

+0

感謝您回覆G5W,代碼是由同事編寫的,因此我很困惑在哪裏更改所需結果的代碼。我遵循你的建議,改變了圖形參數的工作。答案如下:) –

回答

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繪圖

enter image description here