GGFITTEXT:: GEOM_BAR_TEXT涉及Fontface =“ BOLD”时,也不会将文本放在中心中 我想使用ggfittext :: geom_bar_text()将值绘制到具有粗体字体中一定值的水平堆叠栏图中。有一个Fontface美学可用。问题是:我...

问题描述 投票:0回答:1
fontface,标签就不再居中了。

请看一下这个MRE:

bold
这种情况
没有任何粗体标签:
library(ggplot2) library(ggfittext) library(scales)


对于有问题的情况: df2 <- data.frame(cat1 = rep(c("A", "B", "C"), each = 3), cat2 = rep(c("D", "E", "F"), 3), perc = c(0, .6, .4, .26, .24, .5, .3, .3, .4), fface = "plain") ggplot(df2, aes(y = cat1, fill = cat2, x = perc, fontface = fface)) + geom_col() + geom_bar_text(aes(label = percent(perc, accuracy = .1), fontface = fface), position = "stack", place = "centre")

correct plot 发生了什么?

df <- data.frame(cat1 = rep(c("A", "B", "C"), each = 3), cat2 = rep(c("D", "E", "F"), 3), perc = c(0, .6, .4, .26, .24, .5, .3, .3, .4), fface = c("plain", "bold", "plain", "bold", "plain", "plain", "plain", "plain", "bold")) ggplot(df, aes(y = cat1, fill = cat2, x = perc, fontface = fface)) + geom_col() + geom_bar_text(aes(label = percent(perc, accuracy = .1), fontface = fface), position = "stack", place = "centre")

完全相同,除了列中的三个粗体案例外,

df
调用也完全相同。但是,
fface

的标签也关闭了,它们也被切换了。 我错过了什么?这是一个错误吗?谢谢您的帮助!incorrect plot

仅仅是默认问题的问题,在您的情况下,这也考虑了

ggplot()
的问题。要修复您在
cat1 == "C"
aes上明确发出映射,以分组并仅通过
group
变量堆叠:
fontface

r ggplot2 fonts ggfittext
1个回答
0
投票

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.