使用 iris 数据集,用 ggplot2 绘制花萼长度、花萼宽度、花瓣长度、花瓣宽度的箱 线图。
时间: 2023-05-15 11:07:54 浏览: 100
好的,我可以回答这个问题。以下是使用 ggplot2 绘制 iris 数据集中花萼长度、花萼宽度、花瓣长度、花瓣宽度的箱线图的代码:
```R
library(ggplot2)
data(iris)
ggplot(iris, aes(x = Species, y = Sepal.Length, fill = Species)) +
geom_boxplot() +
labs(title = "Boxplot of Sepal Length by Species",
x = "Species", y = "Sepal Length")
ggplot(iris, aes(x = Species, y = Sepal.Width, fill = Species)) +
geom_boxplot() +
labs(title = "Boxplot of Sepal Width by Species",
x = "Species", y = "Sepal Width")
ggplot(iris, aes(x = Species, y = Petal.Length, fill = Species)) +
geom_boxplot() +
labs(title = "Boxplot of Petal Length by Species",
x = "Species", y = "Petal Length")
ggplot(iris, aes(x = Species, y = Petal.Width, fill = Species)) +
geom_boxplot() +
labs(title = "Boxplot of Petal Width by Species",
x = "Species", y = "Petal Width")
```
希望这个回答能够帮到你!