r fontawesome& GGPLOT-图标不起作用?

发布于 2025-02-05 20:00:55 字数 1305 浏览 2 评论 0原文

我在下面粘贴我的代码。我希望使用ggplot与传说中包含用于移动,平板电脑和桌面的图标的图例生产Piechart。但是,尽管绘制了饼图,但我似乎并没有出现这些图标。我觉得这个奇怪的是,好像我例如将桌面图标交换为电视图标一样,它就像其他许多图标一样。我想知道我是否有些问题?


library(tidyverse)
library(grid)
library(emojifont)
library(scales)
library(fontawesome)


load.emojifont("OpenSansEmoji.ttf")
load.fontawesome()


device<-data.frame(`Device`=c("Desktop","Mobile", "Tablet"),
`Proportion`=c(45.7,50,4.3),symbols=c("\UF390","\UE527","\UF3FC"))



# Color palette
pal <- scales::hue_pal()(3)
names(pal) <- c("Desktop", "Mobile", "Tablet")
# Symbol palette
symbols <- c("\UF390", "\UE527","\UF3FC")
names(symbols) <- c("Desktop", "Mobile", "Tablet")

draw_key_symbol <- function(data, params, size) {
data$label <- symbols[names(match.arg(data$fill, pal))]

grid::textGrob(data$label, 0.33,0.33,0.33,
gp = grid::gpar(col = data$fill, 
fontfamily = "fontawesome-webfont", 
fontsize = 3.88 * .pt))
}

ggplot(device, aes(x = "", Proportion, fill = Device)) +
geom_bar(width = 1, stat = "identity", key_glyph = "symbol") +
scale_fill_manual(values = pal) +
coord_polar("y") +
labs(x = NULL, y = NULL)+
theme(axis.text = element_blank(),
axis.ticks = element_blank(),
panel.grid  = element_blank())+
geom_text(aes(label = paste0(
Proportion,"%"
)),
position = position_stack(vjust = 0.5))

I paste my code below. I am looking to produce a piechart using ggplot with the legend containing icons for mobile, tablet and desktop using fontawesome. However, despite the pie chart being plotted, I don't seem to get these icons appearing. I find this odd, as if I for example exchange the desktop icon for a TV icon, it works, as do many other icons. I was wondering whether there is something I'm mising?


library(tidyverse)
library(grid)
library(emojifont)
library(scales)
library(fontawesome)


load.emojifont("OpenSansEmoji.ttf")
load.fontawesome()


device<-data.frame(`Device`=c("Desktop","Mobile", "Tablet"),
`Proportion`=c(45.7,50,4.3),symbols=c("\UF390","\UE527","\UF3FC"))



# Color palette
pal <- scales::hue_pal()(3)
names(pal) <- c("Desktop", "Mobile", "Tablet")
# Symbol palette
symbols <- c("\UF390", "\UE527","\UF3FC")
names(symbols) <- c("Desktop", "Mobile", "Tablet")

draw_key_symbol <- function(data, params, size) {
data$label <- symbols[names(match.arg(data$fill, pal))]

grid::textGrob(data$label, 0.33,0.33,0.33,
gp = grid::gpar(col = data$fill, 
fontfamily = "fontawesome-webfont", 
fontsize = 3.88 * .pt))
}

ggplot(device, aes(x = "", Proportion, fill = Device)) +
geom_bar(width = 1, stat = "identity", key_glyph = "symbol") +
scale_fill_manual(values = pal) +
coord_polar("y") +
labs(x = NULL, y = NULL)+
theme(axis.text = element_blank(),
axis.ticks = element_blank(),
panel.grid  = element_blank())+
geom_text(aes(label = paste0(
Proportion,"%"
)),
position = position_stack(vjust = 0.5))

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文