Changing default colours of a lattice plot by factor

霸气de小男生 提交于 2019-12-24 17:43:12

问题


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

回答1:


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




回答2:


cloud(V3 ~ V1+V2, groups=factor, data=df , pch=19, col=c("black", "grey"))


来源:https://stackoverflow.com/questions/31706240/changing-default-colours-of-a-lattice-plot-by-factor

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!