下面的代码可以将圆环图绘制为附图中的左侧图表,如何将标签更改为右侧图表?谢谢!
library(tidyverse)
pie_data <- data.frame(category=c('A','B','C'),sales=c(70,25,40))
pie_data %>% ggplot(aes(x=1,y=sales,fill=category))+
geom_col()+
scale_fill_brewer(direction = -1)+
geom_text(position=position_stack(vjust=0.5),aes(label=paste0('Category ',category,':',sales)))+
xlim(-1,2)+
coord_polar(theta = 'y')+
theme_void()
Run Code Online (Sandbox Code Playgroud)
您可以使用geom_textpathgeomtextpath 包,该包现在位于 CRAN 上。本质上只需替换geom_text为geom_textpath并将角度设置为 90 度即可。
library(geomtextpath)
library(dplyr)
pie_data <- data.frame(category = c('A', 'B', 'C'),
,sales = c(70, 25, 40))
pie_data %>% ggplot(aes(x = 1, y = sales, fill = category)) +
geom_col() +
scale_fill_brewer(direction = -1) +
geom_textpath(position = position_stack(vjust = 0.5), angle = 90, size = 8,
aes(label = paste0('Category ', category, ':', sales))) +
xlim(-1, 2) +
coord_polar(theta = 'y') +
theme_void()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
435 次 |
| 最近记录: |