I want to change the colors of a dotplot to fade depending on a cumulative probability. I am using hsv to get a list of color codes I want for each individual data point. However, I am having trouble assigning these colors to the plot. Anything so far I have found on the web has been for assigning colors based on groups.
Here is the example:
library(data.table)
library(ggplot2)
#sample of cumulative probabilities
wave <- data.table(
c(1, 1, .9, .6, .2, .02, 0, 0),
c(1, 1, 1, .8, .6, .42, .1, 0),
c(1, 1, 1, .9, .7, .4, .34, .1))
#set up for dot plot
dot <- data.table(rep(c(1:NROW(wave)), NCOL(wave)),
rep(colnames(wave), each = NROW(wave)))
#trying to use saturation in hsv to get prob dependent color fades
fade <- hsv( .9, rev(as.matrix(wave)), .55)
p<-ggplot(
dot, aes(x=V2, y=V1)) +
geom_dotplot(binaxis='y', stackdir='center',
stackratio= .1, dotsize=.7
)
# The following lines don't work:
p+scale_colour_manual(values = fade)
p
p+scale_fill_manual(values = fade)
p
Any help will be appreciated! Thank you.