2017-01-14 6 views
0

Это, вероятно, очень простой вопрос, но я пытаюсь изменить графические параметры в xyplot (ниже). Цель состоит в том, чтобы изменить цвет линии регрессии на красный, а точки данных - на синий.Изменение цвета линии регрессии и точек данных на график XY

Я basicaly попытался код ниже, но когда я добавляю PCH = 19 и седловины = «синий» в код цвета не изменяются.

Если кто-то может помочь, я был бы глубоко благодарен.

код R для сюжета XY

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

enter image description here

+1

Я вижу, что у вас есть 'panel.points (х, у, цв = 1, PCH = 16)' и ' panel.loess (х, у, цв = 1, lwd = 2) 'в вашем примере кода. Вы изменили цвет там? col = 1 указывает черный цвет. Аналогично, вы указываете pch = 16. Это где вы пытались pch = 19? – G5W

+0

Спасибо за ответ G5W, код был написан коллегой, поэтому моя путаница, где можно изменить код для желаемого результата. Я следил за вашими советами и менял графические параметры. Ответ ниже :) –

ответ

1

Heres ответ:

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

enter image description here