0
我正在制作很多地块,并且希望为数据标签设置默认颜色,而不必将color
参数传递给每个geom_text
调用。我可以为绘图标题和坐标轴,但不是数据标签。如何在R ggplot2中设置默认的geom_text颜色?
# Example of how to set default color for other text elements
library(ggplot2)
theme_set(theme_bw() + theme(text = element_text(color = "red"),
axis.text = element_text(color = "red")))
ggplot(mtcars, aes(x = cyl, label = ..count..)) +
geom_bar() +
geom_text(stat = "count") +
labs(title = "title")
一个可能的解决方案,可在http://ggplot2.tidyverse.org/reference/update_defaults.html找到。 'update_geom_defaults(“text”,list(color =“red”)); ggplot(mtcars,aes(mpg,wt))+ geom_text(label = hp)' – bdemarest
@bdemarest作为回答? – dww
@bdemarest这是我正在寻找的解决方案。你应该回答 –