代码拉取完成,页面将自动刷新
library(tidyverse)
# 生成模拟数据
protein_levels <- c(15, 16, 17, 18, 19)
weight_means <- c(8.3, 8.66, 8.92, 9.06, 9.21)
weight_sd <- 0.5
df <- data.frame(
protein_level = rep(protein_levels, each = 50),
weight = c(
rnorm(50, weight_means[1], weight_sd),
rnorm(50, weight_means[2], weight_sd),
rnorm(50, weight_means[3], weight_sd),
rnorm(50, weight_means[4], weight_sd),
rnorm(50, weight_means[5], weight_sd)
)
)
# 绘制图表
ggplot(df, aes(x = protein_level, y = weight, fill = as.factor(protein_level))) +
geom_boxplot() +
labs(x = "Protein Level (%)", y = "Weight (kg)") +
theme_minimal()
# 绘制图表
ggplot(df, aes(x = protein_level, y = weight, fill = as.factor(protein_level))) +
geom_boxplot() +
geom_line(data = data.frame(protein_level = protein_levels, weight_mean = weight_means),
aes(x = protein_level, y = weight_mean),
color = "red",
size = 1.5) +
labs(x = "Protein Level (%)", y = "Weight (kg)") +
theme_minimal()
# 计算每个蛋白质含量下的平均体重
weight_summary <- df %>%
group_by(protein_level) %>%
summarize(weight_mean = mean(weight))
# 绘制图表
ggplot(df, aes(x = protein_level, y = weight, fill = as.factor(protein_level))) +
geom_boxplot() +
geom_line(data = weight_summary,
aes(x = protein_level, y = weight_mean, group = 1),
color = "red",
size = 1.5) +
labs(x = "Protein Level (%)", y = "Weight (kg)") +
theme_minimal()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。