使用geom_textpath给双圆环图添加标签,有些标签颜色和填充颜色相似,所以不是不清楚
using geom_textpath to add labels to a double donut chart , some labels color are smimilar with the fill color ,so not it's not clear
我正在使用 geom_textpath 向双圆环图添加标签,但有些标签颜色与填充颜色相似,所以不是不清楚。如何处理?
library(magrittr)
library(ggplot2)
library(geomtextpath)
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 = year, y = sales, fill = category)) +
geom_col(position = "fill", width = 1, color = "white") +
lims(x = c(2018, 2023)) +
geom_textpath(
position = position_fill(vjust = .5), angle = 90, alpha = 1,
aes(
color = factor(year),
label = paste0(category, ":", sales)
)
) +
coord_polar(theta = "y") +
theme_void()
您可以指定文本色标以突出它们:
pie_data %>% ggplot(aes(x = year, y = sales, fill = category)) +
geom_col(position = "fill", width = 1, color = "white") +
lims(x = c(2018, 2023)) +
geom_textpath(
position = position_fill(vjust = .5), angle = 90, alpha = 1,
aes(
color = factor(year),
label = paste0(category, ":", sales)
), size = 6, fontface = 2
) +
coord_polar(theta = "y") +
scale_colour_manual(values = c("white", "yellow")) +
theme_void()
我正在使用 geom_textpath 向双圆环图添加标签,但有些标签颜色与填充颜色相似,所以不是不清楚。如何处理?
library(magrittr)
library(ggplot2)
library(geomtextpath)
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 = year, y = sales, fill = category)) +
geom_col(position = "fill", width = 1, color = "white") +
lims(x = c(2018, 2023)) +
geom_textpath(
position = position_fill(vjust = .5), angle = 90, alpha = 1,
aes(
color = factor(year),
label = paste0(category, ":", sales)
)
) +
coord_polar(theta = "y") +
theme_void()
您可以指定文本色标以突出它们:
pie_data %>% ggplot(aes(x = year, y = sales, fill = category)) +
geom_col(position = "fill", width = 1, color = "white") +
lims(x = c(2018, 2023)) +
geom_textpath(
position = position_fill(vjust = .5), angle = 90, alpha = 1,
aes(
color = factor(year),
label = paste0(category, ":", sales)
), size = 6, fontface = 2
) +
coord_polar(theta = "y") +
scale_colour_manual(values = c("white", "yellow")) +
theme_void()