我有以下ggplot
library(ggplot2)
library(stringr)
library(tidyverse)
# Create long labels to be wrapped
iris$Species = paste(iris$Species,
"random text to make the labels much much longer than the original labels")
ggplot(iris, aes(Sepal.Length, Sepal.Width, colour=str_wrap(Species,20)))
geom_point()
labs(colour="Long title shortened\nwith wrapping")
theme(legend.key.height=unit(2, "cm"))
我想知道是否可以CSS在legend title. 例如,我想將單詞的字體大小更改wrapping為 12,而其余單詞的字體大小為 10。
任何指標都會非常有幫助。
uj5u.com熱心網友回復:
你可以使用包ggtext和element_markdown你legend.title的一些CSS樣式。你可以修改為任何你想要的。您可以使用以下代碼:
library(ggplot2)
library(stringr)
library(tidyverse)
library(ggtext)
# Create long labels to be wrapped
iris$Species = paste(iris$Species,
"random text to make the labels much much longer than the original labels")
ggplot(iris, aes(Sepal.Length, Sepal.Width, colour=str_wrap(Species,20)))
geom_point()
labs(colour="<span style='font-size:10pt'>Long title shortened with </span><span style='font-size:12pt'>wrapped</span>")
theme(
legend.title = element_markdown()
)
輸出:

如您所見,該單詞wrapped的字體大小為12,而其他單詞的字體大小為10
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/459629.html
上一篇:父母身高和祖父母的位置
下一篇:動態改變彈性容器子元素的順序
