[英]How to build multiple boxplots for 4 variables in R
当然:
也许首先使用“reshape2”库中的“melt”功能。
library(ggplot2)
library(reshape2)
# 1. I dont have your data so i created this fake one:
Your_Data <- data.frame(
"station" = seq(1:100),
"Month_1" = rnorm(100,25,25),
"Month_2" = rnorm(100,30,25),
"Month_3" = rnorm(100,35,25),
"Month_4" = rnorm(100,12,25))
# 2. Then you could transform it into a panel using "melt":
Your_Data <- reshape2::melt(
Your_Data,
id.vars = "station",
variable.name = "Month",
value.name = "Ozone")
# 3. The plot should be something like this
ggplot(Your_Data, aes(Month, Ozone)) +
geom_boxplot() +
# To set labels on the plot
labs(
title = "Boxplot of mean ozone by month",
x = "Month",
y = "Means ozone in \nparts per billion") +
# To center the plot's title
theme(plot.title = element_text(hjust = 0.5))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.