2017-10-08 43 views

回答

2

这是很难知道肯定没有看到的数据,但它似乎像你有四组如下:

# 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() 

现在你获得与三个组的图形。

graph with three groups

相关问题