简体   繁体   中英

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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