【Visualization】饼图,一网打尽!(下)

用ggpuber画个实心饼图

p1 <- ggpubr::ggpie(data = subset(pie_data,year=='2020'), x = "sales", label = "category", color = "white",
fill = "category",lab.pos = "in")+

把图片背景变透明

theme(legend.position = 'none',
panel.background = element_rect(fill = "transparent"), # bg of the panel
plot.background = element_rect(fill = "transparent", color = NA), # bg of the plot
panel.grid.major = element_blank(), # get rid of major grid
panel.grid.minor = element_blank(), # get rid of minor grid
legend.background = element_rect(fill = "transparent"), # get rid of legend bg
legend.box.background = element_rect(fill = "transparent")) # get rid of legend panel bg
p1


![](https://upload-images.jianshu.io/upload_images/28826264-d50e72df0ffe27c2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

```R
p2 <- ggplot(data=subset(pie_data,year=='2021'),aes(x=0,y=sales,fill=category))+
  geom_col(width=1,color='white')+
  geom_text(aes(label = scales::percent(sales/sum(sales))), position = position_stack(vjust = 0.5)) +
  coord_polar(theta = 'y')+
  geom_col(aes(x=-1.2,y=0))+
  theme(legend.position = 'none',
        axis.title = element_blank(),
        axis.text = element_blank(),
        axis.ticks = element_blank(),
        panel.background = element_rect(fill = "transparent"), # bg of the panel
        plot.background = element_rect(fill = "transparent", color = NA), # bg of the plot
        panel.grid.major = element_blank(), # get rid of major grid
        panel.grid.minor = element_blank(), # get rid of minor grid
        legend.background = element_rect(fill = "transparent"), # get rid of legend bg
        legend.box.background = element_rect(fill = "transparent")) # get rid of legend panel bg

p2
library(patchwork)
p2 +inset_element(p1, left = 0.25, bottom = 0.25, right = 0.75, top = 0.75)
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容