2015-08-28 37 views

回答

1

由于您还没有提供示例数据,因此我使用随机数据显示了一个基本示例。 您可以使用功能cut然后boxplot创建中断以将数据分组以创建图表。

基地

set.seed(12) 
y <- rnorm(1000) 
x <- rnorm(1000) 
rng <- seq(-3, 3, 0.5) 
boxplot(y ~ cut(x, breaks = rng), las = 2) 

enter image description here

使用GGPLOT2

set.seed(12) 
y <- rnorm(1000) 
x <- rnorm(1000) 
df <- data.frame(x = cut(x, breaks=rng), y= y) 
ggplot(data = df, aes(x= x , y= y)) + geom_boxplot(aes(fill = x)) 

enter image description here