R xy marking color

Attempted to execute a xy scatter plot with a z value denoted by the color of the xy point.

Data:

1.1, 32.27, 19.4  
1.2, 21.34, 18  
1.4, 47.45, 19.4

R code:

 inp <- scan("beps.txt",list(x=0,y=0,z=0))  
 plot(inp$x, inp$y,pch=".")

Creates a large scatter plot, but I would like the points to be colored with a Z value.

+3
source share
3 answers

Here is an example of a reproducible example that uses ggplot2. If I understand you correctly, I must do what you want.

library(ggplot2)

a = c(1.1, 32.27, 19.4)
b = c(1.2, 21.34, 18)
c = c(1.4, 47.45, 19.4)


df=as.data.frame(rbind(a,b,c))
names(df) = c("x","y","z")
df

p <- ggplot(df, aes(x,y,colour=z)) +geom_point()

All in all, I highly recommend ggplot2 for such things. It really is worth learning a little more. I am still in the middle of the process and understand how much it costs to pay some time in ggplot2. If you do not know the package and the documentation, make sure you check it. The documentation is easy to understand and powerful!

+4

, :

 plot(inp$x, inp$y, pch=".", col=inp$z)

, .

+4

, :

plot(inp$x, inp$y, pch=".", col= heat.colors(30)[inp$z] )

You can, of course, use other color schemes. are you watching? heat.colors

-1
source

Source: https://habr.com/ru/post/1761189/


All Articles