If I understand you correctly, you want to plot two points from two different groups at the same location, but have the two groups being different colors. The alpha of each point will be controlled by a fourth continuous variable, so that the apparent color at each plotted location will be a mix of the two colors, weighted according to this fourth variable.
This kinda works, but not as well as you would hope, for a number of reasons.
To start with, the data you provided is far too unbalanced in favour of the second group, so the points will basically all just appear blue. We therefore need different values of the pixel.intensity
variable to show the effect does work:
library(ggplot2)
df <- structure(list(coordX = c(5, 10, 15, 20, 5, 10, 15, 20), coordY = c(5,
10, 20, 30, 5, 10, 20, 30), variable = structure(c(1L, 1L, 1L,
1L, 2L, 2L, 2L, 2L), .Label = c("var1", "var2"), class = "factor"),
pixel.intensity = c(0, 0.42, 0.51, 0.02, 0.34, 0.1, 0.15,
0.28)), row.names = c(NA, -8L), class = "data.frame")
ggplot(df, aes(x = coordX, y = coordY)) +
geom_point(aes(alpha = pixel.intensity, color = variable), size = 5) +
scale_alpha_identity()
You can see you need a substantial difference in alpha for the points to have anything other than a gray, washed out tinge. Also, if both alphas are low, the points will be very faint.
EDIT
From comments by the OP, it is apparent that we are actually talking about mixing RGB colors here. In that case, suppose we had the following data frame, with red, blue and green intensities scaled between 0 and 1:
red <- rep(c(seq(0, 1, 0.1), rep(1, 10)), 21)
green <- rep(c(rep(1, 10), seq(1, 0, -0.1)), 21)
blue <- rev(rep(c(seq(0, 1, 0.1), rep(1, 10)), each = 21))
red <- red * rev(blue)
green <- green * rev(blue)
x <- rep(0:20, 21)
y <- rep(0:20, each = 21)
df <- data.frame(x, y, red, blue, green)
Then we can plot the rgb values by simply doing this;
df$rgb <- rgb(red, green, blue)
ggplot(df, aes(x, y, color = rgb)) + geom_point(size = 5) + scale_color_identity()
Or if you want to actually emulate pixels:
ggplot(df, aes(x, y, fill = rgb)) + geom_tile() + scale_fill_identity()
Created on 2020-08-02 by the reprex package (v0.3.0)