Plot emojis/emoticons in R with ggplot

时间秒杀一切 提交于 2019-11-29 15:18:05

Because the solution provided seems to depend on the OS, I leave below a rough solution but leave the question open still in case someone has a solution. Thanks @J_F for the support.

library(emojifont)
library(ggplot2)
load.emojifont("EmojiOne.ttf")
quartz()
ggplot(foo, aes(name_emoji, n, label = emoji)) + 
  geom_bar(stat = "identity") +
  geom_text(family = "EmojiOne", size = 6, vjust = -.5) +
  scale_x_discrete(breaks = foo$name_emoji, labels = foo$emoji) +
  theme(axis.title.x=element_blank(),
        axis.text.x=element_blank(),
    axis.ticks.x=element_blank())

It's needed to use quartzjust see this

You can also use this:

library(gridSVG)
ps = grid.export("emoji.svg", addClass=T)

And you get 😎✌️:

I suppose that adjusting the emoticons to the horizontal axis could be a manual solution but for now it is enough for me of emojis. However I leave the question open in case anyone has any idea why the previous solution works on Linux but not on Window or Mac

I tried the following:

foo$name_emoji <- as.factor(foo$name_emoji)
foo$emoji <- as.factor(foo$emoji)

ggplot(foo, aes(name_emoji, n)) + 
  geom_bar(stat = "identity") +
  scale_x_discrete(breaks = foo$name_emoji, labels = foo$emoji) +
  coord_flip()

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!