Change colours in visreg2D regression plot

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-13 02:54:45

问题


A great way to visualise the results of a regression in R is the visreg package. I particularly like the plots that show an interaction with different shades of two colours:

library(visreg)
fit.heat <- lm(Ozone ~ Solar.R + Wind + Temp, data = airquality)
visreg2d(fit.heat, "Wind", "Temp", plot.type = "image")

(from the visreg documentation)

The two colours used are red and blue.

Question

How can I change the colors? Shades of red and blue don't look too well in black and white print, red and blue can't be distinguished. I would be happy with a scale from blue to white for example. Any chances this can be done?


回答1:


You can change the color of the graph by adding a colour argument inside visreg2d function. You can for example use one of the standard R palettes such as terrain.colors() or heat.colors()or modify/create your own palettes e.g. with the package RColorBrewer (as in the example attached).

visreg2d(model, x="RELATEDNESS", y = "Hs_obs", scale = "response", 
xlab = "Relatedness", ylab = "Heterozygosity", main = "Flower abundance", 
zlim = c(0,100), col = colorRampPalette(brewer.pal(9,"Reds"))(20))




回答2:


If you type in

edit(visreg2d)

you will be able to view the color pallet for this function. You can edit here and choose a color combination of your choice.



来源:https://stackoverflow.com/questions/17933064/change-colours-in-visreg2d-regression-plot

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