R:着色图 [英] R: Coloring plots

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

问题描述

我有一些数据,我想绘制(例如 plot(x,y)),但我有一些标准,取决于向量 z 中的值,其看起来像 c(1,0,1,1,1,1,0,NA,0 ,0,...)等。



有一些方法我可以选择什么颜色 1 将会是什么颜色? 0 是什么颜色?



感谢

解决方案

你想要得到一个颜色的向量,只要 code>和 y 向量,例如如下:

  z [is.na(z)] = 2 
zcol = c(red,blue,black)[z + 1]
pre>

然后你可以这样做:

  plot y,col = zcol)


I have some data that I want to plot (e.g. plot(x,y)) but I have some criteria that I want to color by depending on the values in vector z which looks like c(1, 0, 1, 1, 1, 1, 0, NA ,0 ,0, .....) etc.

Is there some way I can choose what color the 1's are going to be and what color the 0's are going to be?

Thanks

解决方案

You want to get a vector of colors as long as the x and y vectors, for example as follows:

z[is.na(z)] = 2
zcol = c("red", "blue", "black")[z + 1]

Then you can simply do:

plot(x, y, col=zcol)

这篇关于R:着色图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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