我对两件事感兴趣:1)同一表中多个子组的总结; 2)基于步骤1中生成的总结的子组的点图。
例如,
如果这是我数据集
data("pbc")
我喜欢按sex
、stage
、ascites
和spiders
生成两个治疗水平1、2的胆固醇总结(chol
)
table(pbc$trt)
1 2
158 154
我可以像这样分开做。
library(Hmisc)
summary(chol ~ sex + stage + ascites + spiders, data = subset(pbc, trt=1))
summary(chol ~ sex + stage + ascites + spiders, data = subset(pbc, trt=2))
这将创建两个单独的摘要。
两个不同的对应图
plot(summary(chol ~ sex + stage + ascites + spiders, data = subset(pbc, trt=1)))
plot(summary(chol ~ sex + stage + ascites + spiders, data = subset(pbc, trt=2)))
我希望摘要在一个表中,两列1列表示trt=1
,第2列表示trt=2
| | | 数量|胆固醇(给药组= 1)|胆固醇(给药组= 2)|
| - ------| - ------| - ------| - ------| - ------|
| 性|米|......| - -| - -|
| | f级|......| - -| - -|
并排绘图。第一张图用于trt = 1,第二张图用于trt = 2
请建议如何缩放Hmisc:::summary.公式,摘要函数,以1)并排显示子组摘要2)并排绘制摘要。谢谢。
1条答案
按热度按时间rjee0c151#
请注意,您当前的总结和图是相同的;尽管使用
subset
和trt
的两个水平,但您发布的两个图是相同的。您可以使用filter
来确定地按trt
的水平进行过滤。首先,我更喜欢使用
gtsummary
来处理我的表,因为你可以使用tbl_continuous
来创建一个单独的表,而不是试图合并两个表;其次,你可能会遇到合并两个图的困难,因为你在Hmisc
汇总对象上使用了基于R的绘图函数;甚至试图将每个图保存到一个对象也会导致NULL
;从长远来看,使用ggplot
并与cowplot::plot_grid
组合可以更容易地重新创建每个图。