Example 1: ggplot2 geom_text reorder
library(dplyr)
library(ggplot2)
data <- tibble(Category = c("Baseball",
"Basketball",
"Football",
"Hockey"),
n = c(45,10,25,20))
ggplot(data, aes (x="", y = n, fill = Category)) +
geom_bar(width = 1, stat = "identity") +
geom_text(aes(label = paste(n, "%")),
position = position_stack(vjust = 0.5))
Example 2: ggplot2 geom_text reorder
library(dplyr)
library(ggplot2)
data <- tibble(Category = c("Baseball",
"Basketball",
"Football",
"Hockey"),
n = c(45,10,25,20))
ggplot(data, aes (x="", y = n, fill = Category)) +
geom_bar(width = 1, stat = "identity") +
geom_text(aes(label = paste(n, "%")),
position = position_stack(vjust = 0.5))
ggplot(data, aes (x="", y = n)) +
geom_bar(aes(fill = Category), width = 1, stat = "identity") +
geom_text(aes(label = paste(n, "%")),
position = position_stack(vjust = 0.5))
ggplot(data, aes (x="", y = n)) +
geom_bar(aes(fill = Category), width = 1, stat = "identity") +
geom_text(aes(fill = Category, label = paste(n, "%")),
position = position_stack(vjust = 0.5))
ggplot(data, aes (x="", y = n)) +
geom_bar(aes(fill = Category), width = 1, stat = "identity") +
geom_text(aes(label = paste(n, "%"), group = Category),
position = position_stack(vjust = 0.5))