2015-08-28 40 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