Consider the following example:
triangle_lines <- data.frame(
X = c(0,0,1,1,0.5,0.5),
Y = c(0,0,0,0,1, 1),
grp = c(1,2,1,3,2,3)
)
df <-
matrix(c(c(0.2,0.5,0.8), c(0.3,0.5,0.1), c(1,5,10)), ncol=3) %>%
as.data.frame()
colnames(df) <- c("x","y", "amount")
ggplot(df, aes(x=x, y=y)) +
geom_point(aes(colour = amount)) +
geom_line(data=triangle_lines, aes(X, Y, group = grp)) +
theme_void()
We have three values: the x coordinates, the y coordinates, and amount that decides the colour values of the scatter points. The points are not equally spaced apart.
Also, I have a triangle. I am attempting to create a gradient heatmap inside this triangle only, filling the entire triangle with heatmap colours based on df$amount. Any idea how to solve this?
P.S. While I am exemplifying with only three points here, this plot will have tens or hundreds of points in real applications.

