3
Do you know if it is possible to get the color palette used in scale_color_*? I would like to get the specific colors (Hex color codes) used with the package paletteer
in each case to then use it in other applications (for example, Join that data with others). What I tried was the following:
library(ggplot2)
library(dplyr)
library(paletteer)
dados <- data.frame(x = sample(seq(0,100), 100, replace = T),
y = sample(seq(0,10), 100, replace = T),
valor = sample(seq(-10,10), 100, replace = T))
plot.1 <- dados %>%
ggplot(aes(x = x, y = y, color = valor))+
geom_point()+
paletteer::scale_color_paletteer_c("ggthemes::Classic Red-White-Green") +
theme_minimal()
After creating object Plot.1, I tried to check if ggplot2 saved colors in the data with plot.1$data
, but that doesn’t happen. Then I tried to check on mapping
with plot.1$mapping$colour
, which returns the following result:
<quosure>
expr: ^cor
env: 000002299B6E1FD0
I don’t know if it’s possible to extract the Hex codes from there. At the end, I would like to have a set with the columns x, y, value and Hex, the latter obtained with the colors of the graphic generated above.
From now on, thank you to those who can help.
perfect, Jorge, the function 'ggplot_build()' was exactly what I was looking for and did not find. Super worth!
– r_rabbit