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這是我正在尋找的解決方案。你應該回答 –