答案 0 :(得分:2)
以下是关于如何解决问题的一些想法
在您的工作目录中下载此图片,并将其命名为man.png
然后,运行以下代码:
library(ggplot2)
library(ggimage)
library(extrafont)
library(dplyr)
loadfonts(device = "win")
df1 <- data.frame(grp=c("0-10","11-20","21-30","31-40","41-50","51-60"),
y=6:1, img=rep("./man.png",6), freq=c(2,5,7,8,4,3))
df2 <- df1[rep(seq_len(nrow(df1)), df1$freq), 1:3]
df2 <- df2 %>% group_by(grp) %>% mutate(x = row_number())
ggplot(df2) + geom_image(aes(x=x, y=y, image=img),size=.08) + theme_void() +
geom_text(data=df1, aes(y=y+0.1, label=freq), x=-0.3,
family="Comic Sans MS", fontface=2, size=8, color="#F26821") +
geom_text(data=df1, aes(y=y-.25, label=grp), x=-0.3,
family="Comic Sans MS", fontface=2) +
xlim(-1,max(df1$freq)+2) + ylim(0,max(df1$y)+1)