I'm struggling with color coding and was hoping you could help.
Here is my issue. I have a dummy dataset:
df <- data.frame(x = 1:10, y = sample(1:100, 10, replace = FALSE, set.seed(2021)))
I first want to plot these data, using a specific color scale:
ggplot(data = df, aes(x = x, y = y, fill = y)) +
geom_point(shape = 21) +
scale_fill_continuous_divergingx(palette = "RdBu",
mid = 50,
rev = TRUE)
Now I would like to use the color that corresponds to, let's say, x = 6 (i.e. y = 70) for another plot. Given certain constraints, I cannot make just another simple ggplot with the same scale to do this, but would instead need to 'hardcode' the hexadecimal value of that specific color, i.e. #e99c8f.
Is there a way to do this, so that I can just then use fill = "#e99c8f" in my other plot?
Hardcoding hex values is easy for certain color scales, e.g. viridis, but I haven't found a way to do it with this one, which I need... :/
Thanks for your help!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…