I'm working in ggplot2
. I was able to create a function. I want to do some modification as change the x-axis label colour based on a column vector
(values 0 and 1).
plot <- function(df) {
a <- ifelse(df$vector == 2, "red", "blue")
ggplot(df, aes(ID, max_value)) +
do stuffs +
theme(axis.text.x=element_text(angle=45, colour = a))
}
It works fine, until add the part colour = a
, then I've got this warning
1: Vectorized input to `element_text()` is not officially supported.
Results may be unexpected or may change in future versions of ggplot2.
And the plot only colour labels in red. Any idea about how to solve that?