如何在R中使用emo包在ggplot2中显示表情符号? [英] How to display emojis in ggplot2 using emo package in R?
问题描述
我正在尝试使用 emo
包使用 ggplot2
绘制一些带有表情符号的图形作为标签。我是从
我的R版本是
> sessionInfo()
R版本3.4.4(2018-03-15)
平台:x86_64-apple-darwin15.6.0(64位)
运行于:macOS Sierra 10.12
使用 emojifont
包:)
了解更多信息
> sessionInfo()
R版本3.5.1(2018-07-02)
平台:x86_64-w64-mingw32 / x64(64位)
运行于:Windows> = 8 x64 (内部版本9200)
I am trying to use ggplot2
to plot some graphs with emojis shown as labels using the emo
package. I've learned it from this post, but it's simply not working.
I have tried the emojifont
package before, but it's a font type that renders emojis in black and white and it requires opening a new graphics device using e.g. quartz()
.
To go around the color problem, Tino has suggested (refer to the post above) using the gridSVG
package, i.e. after creating a new graphics device and plotting with emojifont
, save the graph ps = grid.export("emoji.svg", addClass=T)
on local disk as a .svg
file that renders emojis in a colorful style.
I would really appreciate a solution that (a) gives colorful emojis and (b) showing the graph directly, which is compatible with routine ggplot
use cases.
library(ggplot2)
library(emo)
names = c("smile","school","office","blush","smirk","heart_eyes")
n = length(names):1
e = sapply(names, emo::ji)
dat = data.frame(emoji_name = names, n = n, emoji = e, stringsAsFactors = F)
ggplot(data=dat, aes(emoji_name, n)) +
geom_bar(stat = "identity") +
scale_x_discrete(breaks = dat$emoji_name, labels = dat$emoji) +
coord_flip()
My R version is
> sessionInfo()
R version 3.4.4 (2018-03-15)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12
use the emojifont
package :)
read more here
library(ggplot2)
library(emojifont)
names = c("smile","school","office","blush","smirk","heart_eyes")
n = length(names):1
e = sapply(names, emojifont::emoji)
dat = data.frame(emoji_name = names, n = n, emoji = e, stringsAsFactors = F)
ggplot(data=dat, aes(emoji_name, n)) +
geom_bar(stat = "identity") +
scale_x_discrete(breaks = dat$emoji_name, labels = dat$emoji) +
theme( axis.text.y =element_text( size=20 ) ) +
coord_flip()
> sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
这篇关于如何在R中使用emo包在ggplot2中显示表情符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!