I am interested in two things 1) Summary for multiple subgroups in the same table and 2) dotplot for the subgroups based on the summary generated in step1.
For example ,
if this is my dataset
data("pbc")
I like to generate summary of cholesterol (chol), by sex, stage, ascites and spiders for two treatment levels 1, 2
table(pbc$trt)
1 2
158 154
I can do this separately like this.
library(Hmisc)
summary(chol ~ sex + stage + ascites + spiders, data = subset(pbc, trt=1))
summary(chol ~ sex + stage + ascites + spiders, data = subset(pbc, trt=2))
This creates two separate summaries.
Two different corresponding plots
plot(summary(chol ~ sex + stage + ascites + spiders, data = subset(pbc, trt=1)))
plot(summary(chol ~ sex + stage + ascites + spiders, data = subset(pbc, trt=2)))
I like the summaries to be in one table , two columns 1 column for trt=1 and 2nd column for trt=2
| N | chol (trt=1) | chol (trt=2) | ||
|---|---|---|---|---|
| sex | m | .. | ..... . | .... .. |
| f | .. | ..... . | .... .. |
And the plot side by side. 1st plot for trt=1 , second plot for trt=2
Kindly suggest suggest how to scale the Hmisc:::summary.formula , summary function to 1) show summaries by subgroups side-by-side 2) Plot the summaries side-by-side. Thanks.

Please note that your current summaries and plots are identical; despite using
subsetwith the two levels oftrt, your two posted plots are identical. You can usefilterto definitively filter by the levels oftrt.First, I prefer
gtsummarywith my tables, since you can usetbl_continuousto make one singular table instead of trying to combine two tables. Second, you will likely encounter difficulty trying to combine your two plots since you're using base R plotting functions onHmiscsummary objects. Even trying to save each plot to an object will result inNULL. In the long run, it may be easier to recreate each plot usingggplotand combining withcowplot::plot_grid.