library(ggplot2) #Data Source: https://www.gov.za/about-sa/people-south-africa # Create data data <- data.frame( Health = c("Good/Very Good/Excellent", "Less than Good"), Percent = c(94, 6) ) # Add label text data$Label <- paste0(data$Health, " (", data$Percent, "%)") # Define colors colors <- c("#D44803", "darkgrey") # Pie Chart # ------------------- ggplot(data, aes(x = "", y = Percent, fill = Health)) + geom_bar(width = 1, stat = "identity", color = "black") + coord_polar("y", start = 0) + scale_fill_manual(values = colors) + geom_text(aes(label = paste0(Percent, "%")), position = position_stack(vjust = 0.5), color = "black", size = 5) + labs(title = "Pie Chart with PikBioStat: South African Self-Reported Health Status") + theme_void() + theme(legend.position = "bottom") # Donut Chart # ------------------- ggplot(data, aes(x = 2, y = Percent, fill = Health)) + geom_bar(stat = "identity", width = 1, color = "black") + coord_polar("y", start = 0) + scale_fill_manual(values = colors) + xlim(0.5, 2.5) + # creates the donut hole geom_text(aes(label = paste0(Percent, "%")), position = position_stack(vjust = 0.5), color = "black", size = 6) + labs(title = "Donut Chart with PikBioStat: South African Self-Reported Health Status") + theme_void() + theme(legend.position = "bottom")