xra*_*ash 0 ggplot2 pie-chart geom-text
我正在使用 ggplot2 绘制饼图,并成功地将百分比标签集中在每个切片中
library(dplyr)
library(ggplot2)
library(ggpubr)
library("readxl")
df <- read_excel("Radiocomp.xlsx")
df$Pattern <- factor(cc$Pattern)
str(cc)
GGO <- ggplot(data=df, aes(x = "", y = GGO, fill = Pattern)) +
geom_bar(stat="identity", color = "white") +
geom_text(aes(label = paste0(GGO, "%")), position = position_stack(vjust = 0.5)) +
coord_polar("y") +
theme_void()
GGO
Run Code Online (Sandbox Code Playgroud)
我尝试将百分比标签放在饼图之外以获得更好的可读性
有什么推荐吗?
谢谢
x这可以通过在内部设置美观来实现geom_text,例如x = 1.6将标签放在馅饼的外面。
library(ggplot2)
library(dplyr)
# example data
mpg1 <- mpg %>%
count(class) %>%
mutate(pct = n / sum(n))
ggplot(mpg1, aes(x = "", y = pct, fill = class)) +
geom_bar(stat = "identity", color = "white") +
geom_text(aes(x = 1.6, label = scales::percent(pct, accuracy = .1)), position = position_stack(vjust = .5)) +
coord_polar("y") +
theme_void()
Run Code Online (Sandbox Code Playgroud)

由reprex 包(v0.3.0)于 2020-06-03 创建
| 归档时间: |
|
| 查看次数: |
7054 次 |
| 最近记录: |