R 即使所有组均为空,也显示空组
使用R 即使所有组均为空,也显示空组,r,ggplot2,R,Ggplot2,使用scale\u x\u discrete(drop=FALSE)I设法将空组保留在x轴上的位置上: library(ggplot2) iris_filtered <- subset(iris, Sepal.Length > 7) ggplot(data = iris_filtered, mapping = aes(x = Species, y = Sepal.Width)) + geom_boxplot() + scale_x_discrete(drop = FALSE)
scale\u x\u discrete(drop=FALSE)
I设法将空组保留在x轴上的位置上:
library(ggplot2)
iris_filtered <- subset(iris, Sepal.Length > 7)
ggplot(data = iris_filtered, mapping = aes(x = Species, y = Sepal.Width)) +
geom_boxplot() +
scale_x_discrete(drop = FALSE)
库(ggplot2)
iris(7)
ggplot(数据=虹膜过滤,映射=aes(x=种,y=萼片宽度))+
geom_箱线图()+
比例x离散(下降=假)
除非所有组都为空,否则我会得到:
iris_filtered <- subset(iris, Sepal.Length > 8)
ggplot(data = iris_filtered, mapping = aes(x = Species, y = Sepal.Width)) +
geom_boxplot() +
scale_x_discrete(drop = FALSE)
iris_(8)
ggplot(数据=虹膜过滤,映射=aes(x=种,y=萼片宽度))+
geom_箱线图()+
比例x离散(下降=假)
我希望的产出是:
您可以只指定x轴限制:
iris_filtered <- subset(iris, Sepal.Length > 8)
ggplot(data = iris_filtered, mapping = aes(x = Species, y = Sepal.Width)) +
geom_boxplot() +
scale_x_discrete(drop = FALSE, limits = unique((iris$Species))
ggplot(data = iris_filtered, mapping = aes(x = Species, y = Sepal.Width)) +
geom_boxplot() +
scale_x_discrete(drop = FALSE, limits = c("a","b","c")) +
ylim(min(iris$Sepal.Length), max(iris$Sepal.Length))