Search code examples
rlattice

Changing default colours of a lattice plot by factor


I have been able to create a 3D plot using the cloud function in lattice, however I do not know how to change the colour of points to a factor apart from the default setting of red and black. How to change points and add a regression to a cloudplot (using R)? this question addressed a similar point but I still do not know how to change the default colors. How can I achieve this? What I would like to do is change the colors of the points to grey and black for factor levels 1 and 2, respectively. Also, is there a difference between the two plot formats below?

df <- as.data.frame(matrix(sample(0:20, 3*10, replace=TRUE), ncol=3))
factor <- as.factor(rep(1:2,each = 5))
df <- cbind(df,factor)
library(lattice)
cloud(V3~V1+V2, data = df, pch= 19, #method 1 - red and black filled in points
  col.point = df$factor)
cloud(V3 ~ V1+V2, groups=factor, data=df )#method 2 - open blue and pink points

Solution

  • The colors are determined by the superpose.symbol settings of the current theme. You can change the setting for a call with the par.settings= parmameter. For example

    cloud(V3 ~ V1+V2, groups=factor, data=df, 
        par.settings=list(superpose.symbol=list(col=c("grey","black"))) , auto.key=TRUE)
    

    This returns

    enter image description here