-1
如何避免ggplot在只有三组的情况下制作一个空盒子? ggplot(df, aes(group, value, fill=group)) + geom_boxplot()
填满三组 - 如何居中第三组并删除未使用的盒子
如何避免ggplot在只有三组的情况下制作一个空盒子? ggplot(df, aes(group, value, fill=group)) + geom_boxplot()
填满三组 - 如何居中第三组并删除未使用的盒子
这是很难知道肯定没有看到的数据,但它似乎像你有四组如下:
# Make 3 repetative groups
group <- rep(c("group_1","group_2","group_3"),n)
# Generate values for defined groups
value <- rnorm(length(group), mean = 5, sd = 1)
# Data frame with 1 more group with value
df <- data.frame(c("group_01", group), c(5, value))
colnames(df) <- c("group", "value")
ggplot(df, aes(group, value, fill = group)) + geom_boxplot()
从这个模拟的数据集,我们得到箱线图中this graph如下,这似乎是你的情况。 您应该检查在数据帧的水平,并移除不必要的那些:
# Check for levels
levels(df$group)
# Remove unwanted group
df <- df[df$group != "group_01",]
# Plot the cleaned df
ggplot(df, aes(group, value, fill = group)) + geom_boxplot()
现在你获得与三个组的图形。