I know the ggplot package provides many built-in shape to produce chart. But Can I use ggplot to get the customized chart as the following? Or, which tools should I use?
Asked
Active
Viewed 765 times
1
-
1Possible duplicate of [How to use an image as a point in ggplot?](https://stackoverflow.com/questions/2181902/how-to-use-an-image-as-a-point-in-ggplot) – Z.Lin Nov 18 '17 at 07:38
-
You can do that with the People Graph add-on in Excel – Jul Nov 18 '17 at 08:00
-
Thanks for your help. I guess I just cannot find out the precise keyword to search because of my poor English. – letranger Nov 19 '17 at 09:31
1 Answers
4
Here are some ideas about how you could solve your problem.
Download this image in your working directory naming it as
man.png
.
Then, run this code:
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)

Marco Sandri
- 23,289
- 7
- 54
- 58
-
Thank you for your enthusiastic assistance and demonstration teaching. I think I still have a lot to learn about R. – letranger Nov 19 '17 at 09:36