r fontawesome& GGPLOT-图标不起作用?
我在下面粘贴我的代码。我希望使用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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论