You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为个体插值后生成按5%间隔的relVO2均值点图?

解决方案:按5%功率间隔插值并绘制均值点图

步骤1:按个体插值补全5%间隔数据

针对每个个体生成其功率范围内所有5%倍数的间隔点,再用线性插值补全这些点对应的relVO2值,搞定那些没有5%增量数据的个体:

library(tidyverse)

# 替换成你的实际数据框名称
interpolated_df <- df %>%
  group_by(id) %>%
  # 生成当前个体功率覆盖范围的5%间隔序列
  complete(percent_power = seq(floor(min(percent_power)/5)*5, 
                               ceiling(max(percent_power)/5)*5, 
                               by = 5)) %>%
  # 线性插值补全relVO2
  mutate(relVO2 = approx(x = percent_power, y = relVO2, xout = percent_power)$y) %>%
  ungroup()

步骤2:计算每个5%间隔的relVO2均值

把插值后的数据按5%功率间隔分组,计算每组的平均relVO2,还可以顺便算标准差用来添加误差棒:

summary_df <- interpolated_df %>%
  group_by(percent_power) %>%
  summarise(
    mean_relVO2 = mean(relVO2, na.rm = TRUE),
    sd_relVO2 = sd(relVO2, na.rm = TRUE) # 可选,用于展示数据离散程度
  ) %>%
  ungroup()

步骤3:绘制目标可视化图

用ggplot2绘制点图,可选择连接点成线,也可以添加误差棒:

ggplot(summary_df, aes(x = percent_power, y = mean_relVO2)) +
  # 可选:添加误差棒
  geom_errorbar(aes(ymin = mean_relVO2 - sd_relVO2, ymax = mean_relVO2 + sd_relVO2),
                width = 2, alpha = 0.5) +
  # 绘制均值点
  geom_point(size = 3, color = "steelblue") +
  # 可选:连接点成线
  geom_line(color = "steelblue", linetype = "solid") +
  # 设置坐标轴标签
  labs(x = "百分比功率 (%)", y = "相对摄氧量 (relVO2)") +
  # 简洁主题
  theme_minimal()

注:不需要误差棒的话直接删掉geom_errorbar部分就行;点和线的颜色、大小、线型都能按需调整。

内容的提问来源于stack exchange,提问作者MaxB

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.23 11:15:11