简体   繁体   English

R中的基本2D颜色平滑

[英]Basic 2D color smoothing in R

I have the following data with the following colors 我有以下颜色的以下数据

x = c(2,3,4,2,3,7,8,7,5,6,2,3,6,8,9,10)
y = c(5,6,5,6,5,11,12,11,16,17,12,12,10,5,6,5)
col = sample(c("red","green"),16,rep=T)
plot(x,y,col=col,xlim=c(0,20),ylim=c(0,20),pch=16)

If you run this code you can see it's a 2D plot from 0 to 20 in both the x and y direction. 如果运行此代码,您可以看到它是x和y方向上从0到20的2D图。 I'd like to smoothen the colors which are red and green for now and should stay that way. 我现在想要使红色和绿色的颜色变得平滑,并且应该保持这种状态。 This means that in areas of the plot that have red and green dots, they will become brownish. 这意味着在图中具有红色和绿色点的区域中,它们将变成褐色。 Parts of the plot that currently have no color should be white. 当前没有颜色的绘图部分应该是白色的。 So there should be white areas, red areas, green areas, brownish areas, and areas in between. 所以应该有白色区域,红色区域,绿色区域,褐色区域和中间区域。

More formally speaking, you can think of this as a color interpolation, I suppose. 更正式地说,我想你可以把它想象成颜色插值。

I'm not exactly clear what you're looking for, but perhaps you'd like to make the points larger and transparent so that they can overlap. 我并不完全清楚你在寻找什么,但也许你想让这些点更大更透明,以便它们可以重叠。

library(scales)
plot(x,y,col=alpha(col,0.5),xlim=c(0,20),ylim=c(0,20),pch=16,cex=20)

The alpha() function allows you to make the points transparent. alpha()函数允许您使点透明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM