繁体   English   中英

如何在 R 中为 4 个变量构建多个箱线图

[英]How to build multiple boxplots for 4 variables in R

我需要帮助为我的数据框创建一个多功能框 plot。

数据 = Example_document

属性(变量)= F1、F2、F3、F4、F5

有人可以解释我如何实现这一点并得到如下图吗?

在此处输入图像描述

数据文件名:TestData

$ KF1: 数量 $ KF3: 数量 $ KF4: 数量 $ KF5: 数量 $ KF6: 数量 $ KF7: 数量
$ KF8: 数量 $ KF9: 数量 $ KF10: 数量

'''

当然:

也许首先使用“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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM