1 year ago

#324668

test-img

Ishan Mehta

How do I plot a final fit table as a side by side forest plot?

I have used final fit to derive the following table with univariate and multivariate logistic regression:

> dput(t)
structure(list(subgroup = c("Sex", "Sex", "Age", "Age", "ECOG PS", 
"ECOG PS", "Autoimmune Comorbidity", "Autoimmune Comorbidity", 
"Other (non-autoimmune) comorbidity", "Other (non-autoimmune) comorbidity", 
"Indication", "Indication", "Site", "Site", "Site", "Site", "Site", 
"Site", "Site", "Site", "Sex", "Sex", "Age", "Age", "ECOG PS", 
"ECOG PS", "Autoimmune Comorbidity", "Autoimmune Comorbidity", 
"Other (non-autoimmune) comorbidity", "Other (non-autoimmune) comorbidity", 
"Indication", "Indication", "Site", "Site", "Site", "Site", "Site", 
"Site", "Site", "Site"), level = structure(c(1L, 2L, 3L, 4L, 
5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 
19L, 20L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 
13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L), .Label = c("Sex_Female", 
"Sex_Male", "Age_≤70yrs", "Age_>70yrs", "ECOG PS_0", "ECOG PS_1+", 
"Autoimmune Comorbidity_No", "Autoimmune Comorbidity_Yes", "Other (non-autoimmune) comorbidity_No", 
"Other (non-autoimmune) comorbidity_Yes", "Indication_Adjuvant", 
"Indication_Metastatic / Unresectable", "Site_Cambridge", "Site_Belfast", 
"Site_Cardiff", "Site_Liverpool", "Site_Norwich", "Site_Preston", 
"Site_Southampton", "Site_Taunton"), class = "factor"), Q3W = c("55 (47.4)", 
"61 (52.6)", "48 (41.4)", "68 (58.6)", "64 (55.2)", "52 (44.8)", 
"102 (87.9)", "14 (12.1)", "32 (27.6)", "84 (72.4)", "66 (56.9)", 
"50 (43.1)", "5 (4.3)", "38 (32.8)", "7 (6.0)", "29 (25.0)", 
"12 (10.3)", "4 (3.4)", "11 (9.5)", "10 (8.6)", "55 (47.4)", 
"61 (52.6)", "48 (41.4)", "68 (58.6)", "64 (55.2)", "52 (44.8)", 
"102 (87.9)", "14 (12.1)", "32 (27.6)", "84 (72.4)", "66 (56.9)", 
"50 (43.1)", "5 (4.3)", "38 (32.8)", "7 (6.0)", "29 (25.0)", 
"12 (10.3)", "4 (3.4)", "11 (9.5)", "10 (8.6)"), Q6W = c("57 (35.4)", 
"104 (64.6)", "90 (55.9)", "71 (44.1)", "106 (65.8)", "55 (34.2)", 
"154 (95.7)", "7 (4.3)", "54 (33.5)", "107 (66.5)", "114 (70.8)", 
"47 (29.2)", "26 (16.1)", "18 (11.2)", "52 (32.3)", "21 (13.0)", 
"21 (13.0)", "10 (6.2)", "8 (5.0)", "5 (3.1)", "57 (35.4)", "104 (64.6)", 
"90 (55.9)", "71 (44.1)", "106 (65.8)", "55 (34.2)", "154 (95.7)", 
"7 (4.3)", "54 (33.5)", "107 (66.5)", "114 (70.8)", "47 (29.2)", 
"26 (16.1)", "18 (11.2)", "52 (32.3)", "21 (13.0)", "21 (13.0)", 
"10 (6.2)", "8 (5.0)", "5 (3.1)"), OR = c("1", "1.65 (1.01-2.68, p=0.045)", 
"1", "0.56 (0.34-0.90, p=0.018)", "1", "0.64 (0.39-1.04, p=0.073)", 
"1", "0.33 (0.12-0.82, p=0.021)", "1", "0.75 (0.44-1.27, p=0.291)", 
"1", "0.54 (0.33-0.90, p=0.017)", "1", "0.09 (0.03-0.26, p<0.001)", 
"1.43 (0.39-4.91, p=0.573)", "0.14 (0.04-0.40, p<0.001)", "0.34 (0.09-1.06, p=0.073)", 
"0.48 (0.11-2.28, p=0.340)", "0.14 (0.03-0.50, p=0.004)", "0.10 (0.02-0.38, p=0.001)", 
"1", "1.93 (1.09-3.47, p=0.026)", "1", "0.58 (0.30-1.11, p=0.103)", 
"1", "0.61 (0.30-1.21, p=0.158)", "1", "0.31 (0.09-0.93, p=0.043)", 
"1", "1.60 (0.81-3.19, p=0.175)", "1", "0.76 (0.40-1.45, p=0.400)", 
"1", "0.07 (0.02-0.21, p<0.001)", "1.24 (0.32-4.59, p=0.747)", 
"0.11 (0.03-0.34, p<0.001)", "0.30 (0.08-1.01, p=0.060)", "0.41 (0.08-2.04, p=0.261)", 
"0.10 (0.02-0.39, p=0.001)", "0.06 (0.01-0.26, p<0.001)"), ref = c(TRUE, 
FALSE, TRUE, FALSE, TRUE, FALSE, TRUE, FALSE, TRUE, FALSE, TRUE, 
FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
TRUE, FALSE, TRUE, FALSE, TRUE, FALSE, TRUE, FALSE, TRUE, FALSE, 
TRUE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE), method = structure(c("Univariate Logistic Regression", 
"Univariate Logistic Regression", "Univariate Logistic Regression", 
"Univariate Logistic Regression", "Univariate Logistic Regression", 
"Univariate Logistic Regression", "Univariate Logistic Regression", 
"Univariate Logistic Regression", "Univariate Logistic Regression", 
"Univariate Logistic Regression", "Univariate Logistic Regression", 
"Univariate Logistic Regression", "Univariate Logistic Regression", 
"Univariate Logistic Regression", "Univariate Logistic Regression", 
"Univariate Logistic Regression", "Univariate Logistic Regression", 
"Univariate Logistic Regression", "Univariate Logistic Regression", 
"Univariate Logistic Regression", "Multivariate Logistic Regression", 
"Multivariate Logistic Regression", "Multivariate Logistic Regression", 
"Multivariate Logistic Regression", "Multivariate Logistic Regression", 
"Multivariate Logistic Regression", "Multivariate Logistic Regression", 
"Multivariate Logistic Regression", "Multivariate Logistic Regression", 
"Multivariate Logistic Regression", "Multivariate Logistic Regression", 
"Multivariate Logistic Regression", "Multivariate Logistic Regression", 
"Multivariate Logistic Regression", "Multivariate Logistic Regression", 
"Multivariate Logistic Regression", "Multivariate Logistic Regression", 
"Multivariate Logistic Regression", "Multivariate Logistic Regression", 
"Multivariate Logistic Regression"), .Label = c("Multivariate Logistic Regression", 
"Univariate Logistic Regression")), or = c(1, 1.65, 1, 0.56, 
1, 0.64, 1, 0.33, 1, 0.75, 1, 0.54, 1, 0.09, 1.43, 0.14, 0.34, 
0.48, 0.14, 0.1, 1, 1.93, 1, 0.58, 1, 0.61, 1, 0.31, 1, 1.6, 
1, 0.76, 1, 0.07, 1.24, 0.11, 0.3, 0.41, 0.1, 0.06), low = c(NA, 
1.01, NA, 0.34, NA, 0.39, NA, 0.12, NA, 0.44, NA, 0.33, NA, 0.03, 
0.39, 0.04, 0.09, 0.11, 0.03, 0.02, NA, 1.09, NA, 0.3, NA, 0.3, 
NA, 0.09, NA, 0.81, NA, 0.4, NA, 0.02, 0.32, 0.03, 0.08, 0.08, 
0.02, 0.01), high = c(NA, 2.68, NA, 0.9, NA, 1.04, NA, 0.82, 
NA, 1.27, NA, 0.9, NA, 0.26, 4.91, 0.4, 1.06, 2.28, 0.5, 0.38, 
NA, 3.47, NA, 1.11, NA, 1.21, NA, 0.93, NA, 3.19, NA, 1.45, NA, 
0.21, 4.59, 0.34, 1.01, 2.04, 0.39, 0.26), p = c(NA, 0.045, NA, 
0.018, NA, 0.073, NA, 0.021, NA, 0.291, NA, 0.017, NA, 0.001, 
0.573, 0.001, 0.073, 0.34, 0.004, 0.001, NA, 0.026, NA, 0.103, 
NA, 0.158, NA, 0.043, NA, 0.175, NA, 0.4, NA, 0.001, 0.747, 0.001, 
0.06, 0.261, 0.001, 0.001), p_string = c("", "p=0.045", "", "p=0.018", 
"", "p=0.073", "", "p=0.021", "", "p=0.291", "", "p=0.017", "", 
"p<0.001", "p=0.573", "p<0.001", "p=0.073", "p=0.340", "p=0.004", 
"p=0.001", "", "p=0.026", "", "p=0.103", "", "p=0.158", "", "p=0.043", 
"", "p=0.175", "", "p=0.400", "", "p<0.001", "p=0.747", "p<0.001", 
"p=0.060", "p=0.261", "p=0.001", "p<0.001"), col = c("REF", "UP", 
"REF", "DOWN", "REF", "INSIG", "REF", "DOWN", "REF", "INSIG", 
"REF", "DOWN", "REF", "DOWN", "INSIG", "DOWN", "INSIG", "INSIG", 
"DOWN", "DOWN", "REF", "UP", "REF", "INSIG", "REF", "INSIG", 
"REF", "DOWN", "REF", "INSIG", "REF", "INSIG", "REF", "DOWN", 
"INSIG", "DOWN", "INSIG", "INSIG", "DOWN", "DOWN")), row.names = c("11", 
"12", "2", "1", "5", "6", "3", "4", "9", "10", "7", "8", "14", 
"13", "15", "16", "17", "18", "19", "20", "111", "121", "21", 
"110", "51", "61", "31", "41", "91", "101", "71", "81", "141", 
"131", "151", "161", "171", "181", "191", "201"), class = c("data.frame.ff", 
"data.frame"))

How do I go about making a forest plot, where the left hand side data is shown as a table and the univariate and multivariate odds ratios are shown as forest plots (with error bars as the confidence intervals). I would also like to plot the reference levels as a square forest dot with no error bars. Is this possible?

What I've got so far:

# Plot using t
ggplot(data = t, mapping = aes(x = or, y = level)) +
  geom_vline(xintercept = 1, linetype = 2, color = "red") +
  geom_point(aes(color = col), size = 3) +
  xlab("Adjusted Odds Ratio") +
  ylab("") +
  geom_errorbar(aes(xmax = high, xmin = low, color = col), size = 0.8, width = 0.5) + 
  theme(plot.title.x = element_text(size = 16, face = "bold"),
        axis.text.y = element_blank(),
        axis.text.x = element_text(face = "bold"),
        axis.title.y = element_blank(),
        strip.text.y = element_text(hjust = 0, vjust = 1, angle = 180, face = "bold"),
        legend.title = element_blank()) +
  theme_bw() +
  scale_y_discrete(breaks = c("Age_≤70yrs", "Age_>70yrs",
                            "Sex_Female", "Sex_Male",
                            "Autoimmune Comorbidity_No", "Autoimmune Comorbidity_Yes",
                            "Other (non-autoimmune) comorbidity_No", "Other (non-autoimmune) comorbidity_Yes",
                            "ECOG PS_0", "ECOG PS_1+",
                            "Indication_Adjuvant", "Indication_Metastatic / Unresectable",
                            "Site_Cambridge", "Site_Belfast", "Site_Cardiff", "Site_Liverpool", 
                            "Site_Norwich", "Site_Preston", "Site_Southampton", "Site_Taunton"),
                   labels = c("≤70yrs (Ref)", ">70yrs",
                            "Female (Ref)", "Male",
                            "No (Ref)", "Yes",
                            "No (Ref)", "Yes",
                            "PS 0 (Ref)", "PS 1+",
                            "Adjuvant (Ref)", "Metastatic / Unresectable",
                            "Cambridge (Ref)", "Belfast", "Cardiff", "Liverpool",
                            "Norwich", "Preston", "Southampton", "Taunton"),
                   limits = rev) +
  scale_color_manual(values=c("#375E97","gray70","#FB6542", 'black'),breaks=c("DOWN","INSIG","UP", "REF"), name = "") +
  theme(legend.position = 'none') +
  facet_grid(subgroup ~ method, drop = TRUE)

r

ggplot2

forestplot

0 Answers

Your Answer

Accepted video resources