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

基于scores与metadata数据在同图展示两组样本分布的需求

需求:基于二分类结局绘制特征分布对比图

数据背景

我拥有两个样本完全匹配的R数据框:

  • scores:共2000行、25列,行代表样本,列代表需分析的特征,用于绘制分布图表
  • metadata:包含scores中所有样本的临床信息(如性别、年龄、疾病类型、治疗方案),核心包含3个二分类(是/否)的响应结局列

目标

针对metadata中的每个二分类结局列,绘制该结局“是”组与“否”组的特征分布对比图——将两组的分布(如核密度曲线、直方图)放在同一张图中,直观对比差异。

示例数据

scores示例

Feature_1        Feature_2        Feature_3
Patient_1            0.56             0.11             0.03
Ptient_2             0.605             0.34            0.49
P_3                  0.1              0.76             0.42
12312AX              0.9              0.382            0.12
P_10                 0.89             0.30             0.119
12312BX              0.232            0.118            0.80
12312CX              0.679            0.31             0.789

metadata示例

Gender        Age        Outcome1       Outcome2        Outcome3
Patient_1           M           54            1              0                0
Ptient_2            M           28            0              0                1
P_3                 F           32            1              1                0
12312AX             F           87            0              0                1
P_10                F           43            0              0                1
12312BX             M           90            1              1                0             
12312CX             F           65            1              0                0

预期效果

比如针对Outcome1,绘制Outcome1=1组与Outcome1=0组的Feature_1分布对比——两组分布(如核密度曲线)重叠展示,清晰对比差异。

实际数据子集

scores子集

structure(list(`Feature_1` = c(0.58126387599574, 0.554773857342486, 
0.73811669435931, 0.5993561705421, 0.549993884896126, 0.560952809292699, 
0.514920708901865, 0.668611976328753, 0.579311040856707, 0.627079649056927, 
0.549778821698995, 0.563433551362653, 0.566883741540508, 0.586839499814986, 
0.527874599585146, 0.533974585406425, 0.583020804822263, 0.607821542253184, 
0.570922624085177, 0.531065608748296), `Feature_2` = c(0.671868971517913, 
0.657649690364772, 0.681277871841209, 0.633247301225077, 0.658829966989863, 
0.649553434195565, 0.654719152272398, 0.678510931368968, 0.67606269281911, 
0.657861486037168, 0.656157657102225, 0.654684442044789, 0.660668253143108, 
0.680000904001928, 0.676215636114716, 0.68015840395165, 0.656533748483226, 
0.654344382579621, 0.626207872177309, 0.640129803823085), `Feature10` = c(0.607691853076, 
0.507746766229958, 0.642056075026442, 0.647793952813017, 0.571844979370279, 
0.592183904204232, 0.473827520445559, 0.618900091543045, 0.60656936545554, 
0.60603612041945, 0.510241627095173, 0.564418205496303, 0.561084611266194, 
0.558495659089567, 0.503235910349171, 0.492768739941572, 0.551283907128425, 
0.664425637003928, 0.541804175576185, 0.537845283573044)), row.names = c("Pt1", 
"Pt10", "Pt101", "Pt103", "Pt106", "Pt11", "Pt17", "Pt18", "Pt2", 
"Pt24", "Pt26", "Pt27", "Pt28", "Pt29", "Pt3", "Pt30", "Pt31", 
"Pt34", "Pt36", "Pt37"), class = "data.frame")

metadata子集

structure(list(Response = c("No", "No", "Yes", 
"No", "Yes", "No", "No", "Yes", 
"No", "Yes", "No", "No", "Yes", 
"No", "Yes", "Yes", "No", "Yes", 
"No", "No"), Gender = c("F", "M", 
"F", "M", "M", "F", "M", 
"M", "F", "M", "M", "M", 
"M", "F", "F", "M", "F", 
"F", "M", "F"), Response2 = c(1, 0, 0, 
1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0)), row.names = c("Pt1", 
"Pt10", "Pt101", "Pt103", "Pt106", "Pt11", "Pt17", "Pt18", "Pt2", 
"Pt24", "Pt26", "Pt27", "Pt28", "Pt29", "Pt3", "Pt30", "Pt31", 
"Pt34", "Pt36", "Pt37"), class = "data.frame")

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.30 21:24:27