每次我制作一个固定的条形图时,如果有一个没有数据的部分,那么出于对称的目的,这个图仍然会为它制造一个点,因此看起来这些变量都经过了测试,得到的值是0,但事实并非如此.有没有办法覆盖ggploy.下面是一个示例,其中第8节A3看起来像是记录了0值,但实际上并未在数据集中进行调查.
library(ggplot2)
library(dplyr)
# Your data
data <- data.frame(A = c(1, 2, 3, 1, 2, 3, 1, 2, 1, 2),
B = c(5, 34, 5, 34, 34, 56, 3, 3, 6, 35),
C = c("Light","Light", "Light", "Dark", "Dark", "Dark", "Light","Light", "Dark", "Dark"),
D = c(4, 4, 4, 4, 4, 4, 8, 8, 8, 8))
# Create plots
Plot1 <- ggplot(data, aes(x = A, y = B, fill = C)) +
geom_bar(stat = "identity", position = position_dodge2(preserve = "single")) +
theme_minimal() + theme(legend.position = "right") +
facet_wrap(~D)
Plot1