7

プロットで女性のシンボル ♀ を使用しようとしています。かなりかすんでいるので (実際のグラフではかすかに見えます)、太字にしたかったのです。

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")

かすかな女性のシンボルを持つプロット

私は次のことを試しましたが、どれもうまくいかないようです:

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) 

この投稿も見つけましたが、次のコードを ggplot 内で動作するように変更できるかどうかわかりません。

plot(df)
text( locator(1), "\\VE", vfont=c("sans serif","bold"), xpd=TRUE)  # Venus 
4

1 に答える 1

7

@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")

ここに画像の説明を入力

于 2016-07-13T18:23:25.110 に答える