gpt4 book ai didi

r - 使用 annotate 向 ggplot2 添加粗体女性符号

转载 作者:行者123 更新时间:2023-12-04 09:26:43 25 4
gpt4 key购买 nike

我试图在我的情节中使用女性符号 ♀。它非常微弱(嗯,它在我的实际图表上看起来很微弱),所以我希望让它变得大胆。

df <- data.frame(x = c(0, 1), y = c(0, 1))
ggplot(df, aes(x, y)) + geom_point() +
theme_bw() +
annotate("text", x = 0.5, y = 0.7, label = "2016 ♀",
size = 7, hjust = 0, colour = "grey50")

Plot with faint female symbol

我尝试了以下方法,但似乎都不起作用:
ggplot(df, aes(x, y)) + geom_point() +
annotate("text", x = 0.5, y = 0.7, label = "2016~bold(♀)",
size = 7, hjust = 0, parse = TRUE)

# error message: Error in parse(text = as.character(lab)) : <text>:1:11: unexpected '<'
#1: 2016~bold(<
^

ggplot(df, aes(x, y)) + geom_point() +
annotate("text", x = 0.5, y = 0.7, label = "2016~bold(u2640)",
size = 7, hjust = 0, parse = TRUE)

ggplot(df, aes(x, y)) + geom_point() +
annotate("text", x = 0.5, y = 0.7, label = "2016~bold(\u2640)",
size = 7, hjust = 0, parse = TRUE)

我还找到了 this post ,但我不确定是否可以修改以下代码以在 ggplot 中工作?
plot(df)
text( locator(1), "\\VE", vfont=c("sans serif","bold"), xpd=TRUE) # Venus

最佳答案

@Axeman 的评论帮助我找到了答案——我没有意识到你可以加载其他包来为 ggplot2 获取更多字体。谢谢!我使用了以下代码:

install.packages("extrafont")
library(extrafont)
font_import() # Prepare for this to take several minutes
loadfonts(device = "win")

ggplot(df, aes(x, y)) + geom_point() +
theme_bw() +
annotate("text", x = 0.5, y = 0.7, label = "2016 ♀",
size = 7, hjust = 0, colour = "grey50", family = "Calibri", fontface = "bold")

enter image description here

关于r - 使用 annotate 向 ggplot2 添加粗体女性符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38355061/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com