#r #ggplot2
#r #ggplot2
Вопрос:
Я хочу создать круговую диаграмму со столбцом факторов, используя ggplot, я хочу показать процент, частоту и пробную фазу для каждого: это мой код:
library(ggplot2)
library(ggrepel)
library(dplyr)
library(cowplot)
#Retrieve data
figvac <- read.csv(url("https://raw.githubusercontent.com/learnseq/learning/main/vaccinedev.txt"),sep = 't',header = TRUE)
library(repr, warn.conflicts = FALSE)
options(repr.plot.width=17, repr.plot.height=10)
ggplot(figvac, aes(x="", fill=factor(figvac[, 2] ))) geom_bar(width = 1) coord_polar("y", start=0)
Я пытался
geom_text(aes(label = paste(round(factor(figvac[, 2] / sum(factor(figvac[, 2]) * 100, 1), "%"))),
position = position_stack(vjust = 0.5))
theme_classic()
theme(plot.title = element_text(hjust=0.5),
axis.line = element_blank(),
axis.text = element_blank(),
axis.ticks = element_blank())
labs(fill = "Category",
x = NULL,
y = NULL,
title = "Pie Chart of Vaccines")
coord_polar("y")
Но это не сработало.
Ответ №1:
Вы хотите fill=factor(Mechanism)
Ответ №2:
Это должно сработать:
library(ggplot2)
figvac <- read.csv(url("https://raw.githubusercontent.com/learnseq/learning/main/vaccinedev.txt"),sep = 't',header = TRUE)
ggplot(figvac, aes(x=Mechanism, fill=Mechanism))
geom_bar(width = 1)
coord_polar()