R中的emojifont包介绍
在本文中,我们将了解如何在 R 中使用 emojifont 包。该包旨在将 emoji 字体引入 R 编程语言。
我们将看看如何使用 emojifont 包搜索和打印表情符号。
安装:
要安装此软件包,请在终端中键入以下命令。
install.packages(“emojifont”)
R中的表情符号字符
现在我们已经安装了 emojifont 包,所以我们将使用库(emojifont)导入它。要打印 emoji,我们将使用emoji(“emojiname”)来搜索 emoji,我们将使用 search_emoji(“name”),这将返回所有相关的 emoji,我们会将其存储为列表并使用emoji() 进行打印。
R
# importing package
library(emojifont)
# printing joy emoji
emoji("joy")
# searching emoji
list <- c(search_emoji("joy"))
# printing all the emoji's in the list
emoji(list)
R
# importing package
library(emojifont)
# getting random sample of emojis
list = c(sample_emoji(10))
# printing all the emoji's in list
emoji(list)
R
# importing package
library(emojifont)
# generating random numbers for x-axis
set.seed(200)
# gets 10 random point on x axis from
# seed
x <- rnorm(10)
# generating random numbers for y-axis
set.seed(100)
# gets 10 random point on y axis from
# seed
y <- rnorm(10)
# Plotting a blank chart in order to
# clear the screen
# if any chart is already opened
# or the emoji's will overlap
plot(x, y, cex = 0)
# plotting chart
text(x, y, labels=emoji('joy'), cex=3.5, col='red',
family='EmojiOne')
R
# importing package
library(emojifont)
library(ggplot2)
# generating random numbers for x-axis
set.seed(200)
# gets 10 random point on x axis from
# seed
x <- rnorm(10)
# generating random numbers for y-axis
set.seed(100)
# gets 10 random point on y axis from
# seed
y <- rnorm(10)
# defining data frame
data <- data.frame(x=x,y=y)
# plotting chart
ggplot(data,aes(x, y, color="red", label=emoji('joy'))) +
geom_text(family="EmojiOne", size=6)
R
# importing package
library(emojifont)
library(ggplot2)
# plotting emoji
ggplot() + geom_emoji("joy", color='red') + theme_void()
R
# importing package
library(emojifont)
library(ggplot2)
# plotting emoji
ggplot() + geom_fontawesome("fa-desktop",
color='black') + theme_void()
输出:
获取表情符号的随机样本
为了获得随机表情符号,我们将使用sample_emoji(x)来获取随机表情符号。
R
# importing package
library(emojifont)
# getting random sample of emojis
list = c(sample_emoji(10))
# printing all the emoji's in list
emoji(list)
输出:
R图中的表情符号
方法 1:使用基图
plot() 用于绘制 x 和 y 为坐标的图表。
plot(x, y, …)
“…” are the arguments passed to methods like graphicals parameters.
text() 用于绘制向量标签。其中 x,y 坐标,
text (x, y = NULL, labels = seq_along(x$x), cex = 1, col = NULL, …)
R
# importing package
library(emojifont)
# generating random numbers for x-axis
set.seed(200)
# gets 10 random point on x axis from
# seed
x <- rnorm(10)
# generating random numbers for y-axis
set.seed(100)
# gets 10 random point on y axis from
# seed
y <- rnorm(10)
# Plotting a blank chart in order to
# clear the screen
# if any chart is already opened
# or the emoji's will overlap
plot(x, y, cex = 0)
# plotting chart
text(x, y, labels=emoji('joy'), cex=3.5, col='red',
family='EmojiOne')
输出:
方法2:使用ggplot
ggplot()用于绘制图表,其中 data 是我们的数据框,aes() 描述了内容将如何绘制在屏幕上。
ggplot(data = NULL, mapping = aes(), …)
R
# importing package
library(emojifont)
library(ggplot2)
# generating random numbers for x-axis
set.seed(200)
# gets 10 random point on x axis from
# seed
x <- rnorm(10)
# generating random numbers for y-axis
set.seed(100)
# gets 10 random point on y axis from
# seed
y <- rnorm(10)
# defining data frame
data <- data.frame(x=x,y=y)
# plotting chart
ggplot(data,aes(x, y, color="red", label=emoji('joy'))) +
geom_text(family="EmojiOne", size=6)
输出:
方法三:使用 Geom_emoji
geom_emoji()用作可视化表情符号的包装器。
R
# importing package
library(emojifont)
library(ggplot2)
# plotting emoji
ggplot() + geom_emoji("joy", color='red') + theme_void()
输出:
方法4:字体真棒
geom_fontawesome()用作可视化 fontawesome 的包装器。
R
# importing package
library(emojifont)
library(ggplot2)
# plotting emoji
ggplot() + geom_fontawesome("fa-desktop",
color='black') + theme_void()
输出: