filmov
tv
Keep Unused Factor Levels in ggplot2 Barplot in R (Example) | Barchart with Empty Values in Category

Показать описание
R code of this video:
y = c(2, 0, 4, 3, 0))
data <- data[data$y > 0, ]
data$x
library("ggplot2") # Load ggplot2 package
ggp <- ggplot(data, aes(x, y, fill = x)) + # Create barchart without 0-levels
geom_bar(stat = "identity")
ggp # Draw barplot
ggp + # Create barchart with empty factors
scale_x_discrete(drop = FALSE)
Follow me on Social Media:
y = c(2, 0, 4, 3, 0))
data <- data[data$y > 0, ]
data$x
library("ggplot2") # Load ggplot2 package
ggp <- ggplot(data, aes(x, y, fill = x)) + # Create barchart without 0-levels
geom_bar(stat = "identity")
ggp # Draw barplot
ggp + # Create barchart with empty factors
scale_x_discrete(drop = FALSE)
Follow me on Social Media:
Комментарии