更改 visreg2D 回归图中的颜色 [英] Change colours in visreg2D regression plot

查看:43
本文介绍了更改 visreg2D 回归图中的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 R 中可视化回归结果的一个好方法是 visreg 包.我特别喜欢显示两种颜色不同深浅相互作用的图:

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")

(来自 visreg 文档)

(from the visreg documentation)

使用的两种颜色是红色和蓝色.

The two colours used are red and blue.

问题

如何更改颜色?红色和蓝色的色调在黑白打印中看起来不太好,无法区分红色和蓝色.例如,我会对从蓝色到白色的比例感到满意.有没有可能做到这一点?

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?

推荐答案

您可以通过在 visreg2d 函数中添加颜色参数来更改图形的颜色.例如,您可以使用标准 R 调色板之一,例如 terrain.colors()heat.colors() 或修改/创建自己的调色板,例如带有 RColorBrewer 包(如所附示例中所示).

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))

这篇关于更改 visreg2D 回归图中的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆