Closed yuliaUU closed 2 years ago
I just discovered the same issue and error message while building a shiny app. If I do not load the ggthemr package, the plot works as intended (as is the case in your example).
Without having investigated further, it appears that ggthemr somehow overwrites the color definition in ggplot aes and expects a named color input rather than a factor variable.
I'm having a similar issue as well!
I was having the same issue and may have found a workaround. If used something like plt + scale_color_viridis_d()
on the example it would work. Whereas if I used plt + scale_color_discrete()
I would get the unknown colour error.
With that in mind I created a function that takes the current swatch()
object as a basis for a new pal function:
swatch_pal <- function() {
function(n) {
if(n > length(swatch()) - 1) warning(paste("Swatch only has", length(swatch())-1), " colours")
color_list <- as.character(swatch()[2:length(swatch())])
return(color_list[1:n])
}
}
scale_colour_ggthemr_d <- function(...) {
ggplot2::discrete_scale(
"colour", "ggthemr_swatch_color",
swatch_pal(),
...
)
}
scale_color_ggthemr_d <- scale_colour_ggthemr_d
Now I can do plt + scale_colour_ggthemr_d()
and it works fine. It will also dynamically change colors if you modify the swatch() object, either through changing theme or creating your own custom palette
Had the same issue. Thanks very much, Matt-Int, for solving and sharing!
having the same issue
It looks as if this is caused by ggplot2, as per the issue at tidyverse/ggplot2#4149. So I don't know if there's much that can be done in ggthemr directly.
Thanks everyone in this thread for raising this issue.
@Matt-Int, thanks for sharing your solution here. Will have to look into how to have a workaround in ggthemr
. I was planning to resubmit to CRAN but then also encountered this issue... I am thinking postponing CRAN submission for now, and resubmit after https://github.com/tidyverse/ggplot2/issues/4149 is solved.
@Matt-Int if you have a solution handy by changing the ggthemr pkg directly, feel free to contribute too!
Amy
Looks like the upstream ggplot2 issue referenced earlier has been closed. I tried the initial code with the latest build of ggplot2 and no longer get the error Error: Unknown colour name: post
.
However, the colour is not updated and it seems to use the default ggplot colours instead. I've tried finding what is going on but when I use plt + getOption("ggplot2.discrete.colour")()
I get the same (correct) result as when using the plt + scale_colour_ggthemr_d()
.
I am trying to apply the dust theme:
but I get an error
Error: Unknown colour name: post
I understand that somehow it is not able to apply the color theme to the column that is used for plotting. I am not sure how to specify it