-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
axis.text.y and "Vectorized input to element_text()
is not officially supported" - is there any smart way to address it?
#4533
Comments
element_text()
is not officially supported."element_text()
is not officially supported" - is there any smart way to address it?
Just to provide a reprex, the following triggers the warning: library(ggplot2)
ggplot(mtcars, aes(wt, mpg)) +
geom_point() +
theme(axis.text.y = element_text(colour = c("red", "green", rep("black", 4))))
#> Warning: Vectorized input to `element_text()` is not officially supported.
#> Results may be unexpected or may change in future versions of ggplot2. In these types of cases I usually find the library(ggtext)
library(glue)
ggplot(mtcars, aes(wt, mpg)) +
geom_point() +
scale_y_continuous(
labels = function(x) {
colours <- c("red", "green", rep("black", length(x) - 2))
glue("<span style='color:{colours}'>{x}</span>")
}
) +
theme(axis.text.y = element_markdown()) Created on 2021-06-27 by the reprex package (v1.0.0) Given that you already give the labels verbatim, you could put the html tags around it. |
Oh, this is marvellous. Thank you very much for this solution. I can only hope that the ggtext package will be maintained for a long time (not abandoned and removed from the CRAN) in the future, because I will need to employ it in my workflow (I work in the medical industry, where the aspect of persistence of solutions is critical). So, although this solution is clean, elegant, easy and I am going to use it, but, honestly, I would prefer to have it done entirely in the ggplot2 - just to limit the external dependencies. Maybe the Authors, @hadley , @clauswilke, @thomasp85, who decide on the final "shape" of the ggplot2 package could consider preserving this, or add a way to achieve that effect other way? This would be really nice to have this feature without employing third-party packages. |
Sorry, we already decided not to allow vectorized inputs here. That's why you see the warning. For more context, please refer to the discussion around #3492 (comment). |
@yutannihilation Sorry to open this again: Is ggtext still the recommended solution? Like @Generalized I'm also a bit skeptical about using ggtext given that it has not received very little development activity since its initial release. Moreover, it's been ~5 years since the ggplot2 deprecation cycle started, are there any plans of this going away anytime soon? |
If ggtext solves your problem go ahead and use it, but I don't expect that it'll see much development going forward. @thomasp85 is approaching the problem in a much more systematic way in his marquee package and so you may want to check that out: https://cran.r-project.org/web/packages/marquee/index.html |
@clauswilke Thank you for the heads-up, just checked it out! Unfortunately marquee does not seem to provide a sustainable solution to the vectorized input problem I'm looking for though, given that there's still a warning for this use case library(ggplot2)
gg <- ggplot(data = mtcars, aes(x = disp, y = mpg)) +
geom_line() +
labs(subtitle = c("left-aligned subtitle", "right-aligned subtitle"))
gg +
theme(
plot.subtitle = marquee::element_marquee(hjust = c(0, 1))
)
#> Warning: Vectorized input to `element_text()` is not officially supported.
#> ℹ Results may be unexpected or may change in future versions of ggplot2. Created on 2024-08-27 with reprex v2.1.0 Was mostly getting at this use case here wilkelab/ggtext#116 |
The original example here was about coloring and using the marquee package you can give each label its own color without needing to vectorize input to |
Is there any way to achieve the effect presented on the screenshot, made with the instructions I show below - which triggers a warning?
Description of the effect to achieve:
There is a set of faceted Kaplan-Meier curves. The study sponsor wants each panel to have it's own risk table (it cannot be negotiated - the risk table must be shown there and not elsewhere).
Each row of the risk table is linked to a corresponding curve by label and color.
I also had to make the font a bit smaller.
With the code I made it works perfectly and was accepted by the study sponsor.
which is made with this code:
What bothers me is the warning (as mentioned in the title) I get all the time.
This is triggered by this line
Is there any simple, elegant solution allowing me to obtain this very effect without the warning?
I read, that you may remove this awesome feature (vectorization on the element_text) some day - which would be really a pity, so the code will break. Please guide me how to achieve the same with similar efforts, as this template will be used by me very often.
The text was updated successfully, but these errors were encountered: