1 Star 0 Fork 0

bioproj/Rcode

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
linear_regression_boxplot.R 1.47 KB
一键复制 编辑 原始数据 按行查看 历史
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()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
R
1
https://gitee.com/bioproj/rcode.git
git@gitee.com:bioproj/rcode.git
bioproj
rcode
Rcode
master

搜索帮助