ggplot use small pie charts as points with geom_point

烂漫一生 提交于 2019-11-30 00:44:40

Using a plot as the shape for a point is tricky. However, you can side step the issue and get very close to your mockup using facet_grid():

ggplot(temp) + 
  geom_bar(aes(x=1, y=Score), stat="identity") + 
  facet_grid(Exercise~Name) + 
  coord_polar(theta = "y") +
  scale_y_continuous(breaks = NULL) +
  scale_x_continuous(name = element_blank(), breaks = NULL)

First, modify your original data frame to have first 6 rows containing original score and last 6 rows contains 1 minus original score. Then added column group containing levels for those two groups.

temp <- data.frame(Exercise=c(1, 1, 1, 2, 2, 2), 
                   Name=c(1, 2, 3, 1, 2, 3), Score=c(0.2, 0.5, 0.3, 0.9, 1.0, 0.6))
temp<-rbind(temp,temp)
temp$Score[7:12]<-1-temp$Score[1:6]
temp$group<-rep(c("poz","neg"),each=6)

coord_polar() is used to make piecharts from barplot and then facet_grid() to make six small plots. theme() is used to remove axis, facet labels, gridlines.

ggplot(temp,aes(x = factor(1),y=Score,fill=group)) + 
  geom_bar(width = 1, stat = "identity") + facet_grid(Exercise~Name)+
  coord_polar(theta = "y") +
  scale_fill_manual(values = c("black", "grey")) +
  theme_bw() + scale_x_discrete("",breaks=NULL) + scale_y_continuous("",breaks=NULL)+
  theme(panel.border=element_blank(),
        strip.text=element_blank(),
        strip.background=element_blank(),
        legend.position="none",
        panel.grid=element_blank())

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!