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

如何用R可视化三个参数与GR分组的关系?求其他展示方式

其他数据展示方式推荐(GR与CYT/EMT/PRO的关系)

针对你已有的数据,除了分组柱状图,还有以下几种更能体现数据特征的可视化方式:

1. 箱线图(展示分组分布差异)

箱线图可以直观呈现不同GR分组下各参数的中位数、四分位距、极值和异常值,比柱状图更能反映数据的离散程度和分布特征。

library(ggplot2)
library(reshape2)

df_long <- reshape2::melt(df, id.vars = "GR")

ggplot(df_long, aes(x = variable, y = value, fill = GR)) +
  geom_boxplot(position = position_dodge(0.9)) +
  labs(title = "GR分组下各参数的分布",
       x = "参数类型",
       y = "参数值") +
  theme_minimal()

2. 小提琴图(结合分布密度与统计特征)

小提琴图在箱线图的基础上叠加了核密度曲线,既能展示数据的统计量,又能呈现分布的形状,适合观察两组数据的分布模式差异。

ggplot(df_long, aes(x = variable, y = value, fill = GR)) +
  geom_violin(position = position_dodge(0.9), alpha = 0.7) +
  geom_boxplot(width = 0.2, position = position_dodge(0.9), color = "black") +
  labs(title = "GR分组下各参数的分布密度",
       x = "参数类型",
       y = "参数值") +
  theme_minimal()

3. 散点抖动图(展示原始数据点)

直接展示所有原始数据点,通过轻微抖动避免重叠,能清晰看到每个样本的具体数值,适合样本量不大的场景(你的数据共14个样本,非常适用)。

ggplot(df_long, aes(x = variable, y = value, color = GR)) +
  geom_jitter(width = 0.2, size = 2, alpha = 0.8) +
  labs(title = "GR分组下各参数的原始数据分布",
       x = "参数类型",
       y = "参数值") +
  theme_minimal()

4. 分面密度图(对比分组分布趋势)

将每个参数单独分面,用密度曲线展示不同GR分组的分布趋势,便于直观比较两组数据的分布重叠度和峰值位置。

ggplot(df_long, aes(x = value, fill = GR, color = GR)) +
  geom_density(alpha = 0.3) +
  facet_wrap(~ variable, scales = "free_x") +
  labs(title = "各参数在GR分组中的分布密度",
       x = "参数值",
       y = "密度") +
  theme_minimal()

5. 箱线+散点组合图(兼顾统计与原始数据)

同时展示箱线图的统计信息和散点图的原始数据点,既可以了解整体分布特征,又能看到个体样本的数值情况,信息更全面。

ggplot(df_long, aes(x = variable, y = value, fill = GR)) +
  geom_boxplot(position = position_dodge(0.9), alpha = 0.7) +
  geom_jitter(position = position_dodge(0.9), color = "black", size = 1.5) +
  labs(title = "GR分组下各参数的分布与原始数据",
       x = "参数类型",
       y = "参数值") +
  theme_minimal()

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.05 01:17:39