是否可以制作不同字体的指南?我正在尝试绘制我的多变量数据,除了颜色代码之外,我还想将一些指南设为粗体。 这是一个可重现的例子
library("ggpubr")
library("reshape2")
iris.melt <- melt(iris)
ggboxplot(data = iris.melt, x = "variable", y= "value", add = "jitter",
add.params = list(color = "Species"), legend = "bottom") +
theme(legend.text = element_text(face = "italic")) +
guides(col = guide_legend(override.aes = list(size=2), label.position = "bottom"))
产生
我试着只突出一个物种
ggboxplot(data = iris.melt, x = "variable", y= "value", add = "jitter",
add.params = list(color = "Species"), legend = "bottom") +
theme(legend.text = element_text(face = c("plain","italic","plain")) +
guides(col = guide_legend(override.aes = list(size=2), label.position = "bottom"))
但“element_text()
的向量化输入不受官方支持。”
有没有办法自定义图例中的个别项目?
最佳答案
我不认为有办法单独设置主题组件,但有一个解决方法,即使用表达式作为标签。这样您就可以将任何单个标签设为粗体:
library("ggpubr")
library("reshape2")
iris.melt <- melt(iris)
one_bold_label <- expression("Setosa", bold(paste("Versicolor")), "Virginica")
ggboxplot(data = iris.melt, x = "variable", y= "value", add = "jitter",
add.params = list(color = "Species"), legend = "bottom") +
theme(legend.text = element_text(face = "italic")) +
scale_colour_manual(labels = one_bold_label, values = c("#F8766D", "#00BA38", "#619CFF")) +
scale_fill_manual(labels = one_bold_label, values = c("white", "white", "white"))
由 reprex package 创建于 2020-05-31 (v0.3.0)
关于r - 我可以自定义 ggplot 图例中的个人项目吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62120943/