-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Closed
Labels
bugan unexpected problem or unintended behavioran unexpected problem or unintended behaviorhelp wanted ❤️we'd love your help!we'd love your help!themes 💃
Description
When using guide = guide_legend(...) to change non-angle parameters of label.theme or title.theme, an error is generated due to non-NULL value for angle.
Here are examples trying to set face, without setting angle:
library(ggplot2)
ggplot(iris, aes(x = Sepal.Length, y = Petal.Length, color = Species)) +
geom_point() +
scale_color_discrete(guide = guide_legend(label.theme = element_text(face = "italic")))
#> Error in element_grob.element_text(element = label.theme, label = label, : Text element requires non-NULL value for 'angle'.
ggplot(iris, aes(x = Sepal.Length, y = Petal.Length, color = Species)) +
geom_point() +
scale_color_discrete(guide = guide_legend(title.theme = element_text(face = "italic")))
#> Error in element_grob.element_text(guide$title.theme %||% calc_element("legend.title", : Text element requires non-NULL value for 'angle'.(reprex inserts an 'empty plot placeholder' here, despite the code above errors...)
Trying to set size, hjust or vjust without setting angle leads to the same error.
To change any non-angle parameters, we need to set angle as well. E.g.:
ggplot(iris, aes(x = Sepal.Length, y = Petal.Length, color = Species)) +
geom_point() +
scale_color_discrete(guide = guide_legend(label.theme = element_text(face = "italic", angle = 0))) In contrast, there is no need to explicitly set any of the other NULL arguments in element_text when setting angle only:
ggplot(iris, aes(x = Sepal.Length, y = Petal.Length, color = Species)) +
geom_point() +
scale_color_discrete(guide = guide_legend(
label.theme = element_text(angle = -5)))
ggplot(iris, aes(x = Sepal.Length, y = Petal.Length, color = Species)) +
geom_point() +
scale_color_discrete(guide = guide_legend(
title.theme = element_text(angle = 5))) Metadata
Metadata
Assignees
Labels
bugan unexpected problem or unintended behavioran unexpected problem or unintended behaviorhelp wanted ❤️we'd love your help!we'd love your help!themes 💃



