-2

I would like to plot a scatterplot of two variables using three columns as reference for the colour of the point.

In this case, each point of the graphic is represented by a single row.

Each row has five attributes: x, y, R, G and B.

I created an example of the result I expect using excel, since one can change the colours manually.

This is not an option for me, for I have thousands of samples.

Given the following table:

| x | y | R | G | B |   
+---+---+---+---+---+
| 2 | 2 |255|255| 0 |    
| 2 | 2 |255|255| 0 |    
| 5 | 1 | 0 |255| 0 |    
| 4 | 3 | 0 | 0 |255|    
| 1 | 5 |255| 0 |255|

I expect to generate this graphic:

Expected graphic result

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

0

finally got it.

d0 <- c(2, 2, 255, 255, 0)
d1 <- c(5, 1, 0, 255, 0)
d2 <- c(4, 3, 0, 0, 255)
d3 <- c(1, 5, 255, 0, 255)

data <- rbind(d0,d1,d2,d3)
print(data)

x <-data[,1]
print(x)

y <-data[,2]
print(y)

colors <-data[,c(3,4,5)]
colors_norm <- colors * (1/255) 
print(colors_norm)

colors_hex <- rgb(colors_norm) 
print(colors_hex)

# Simple Scatterplot
plot(x,y, main="Color Scatterplot", xlab="x", ylab="y ", pch=19, col=colors_hex)