[英]In ggplot2, how to add a white hole in the middle of the pie chart
ggplot2,如何在饼图中间加一个白洞? 电流plot请参考下面的代码(左图)。 谢谢!
library(tidyverse)
pie_data <- data.frame(category=c('A','B','C','A','B','C'),
year=c(2020,2020,2020,2021,2021,2021),
sales=c(40,30,20,10,15,10))
pie_data %>% ggplot(aes(x=factor(year),y=sales,fill=category))+
geom_col(position='fill',width=1,color='white')+
coord_polar(theta = 'y')+
theme_void()
只需扩大 x 轴的范围(如果不将年份转换为一个因素,这样做会更容易):
pie_data %>% ggplot(aes(x = year, y = sales, fill = category))+
geom_col(position = 'fill', width = 1, color = 'white') +
coord_polar(theta = 'y') +
lims(x = c(2019, 2022)) +
theme_void()
您可以通过更改上述代码中的 2019 来控制白洞的大小。 年份越早,洞越大:
pie_data %>% ggplot(aes(x = year, y = sales, fill = category))+
geom_col(position = 'fill', width = 1, color = 'white') +
coord_polar(theta = 'y') +
lims(x = c(2017, 2022)) +
theme_void()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.