Overlap visualizations with spec_pointrange/kableExtra in one column

14 views Asked by At

In this example (adapted from the kableExtra website), I want to add a column to a table to plot the coefficients and confidence intervarls of two estimations per row (let's say to compare men and women). However, when I plot it the plot appears in two different columns despite specifying both to be in the same col.

coef_table <- data.frame(
      Variables = c("var 1", "var 2", "var 3"),
      Coefficients = c(1.6, 0.2, -2.0),
      Conf.Lower = c(1.3, -0.4, -2.5),
      Conf.Higher = c(1.9, 0.6, -1.4)
) 

coef_table2 <- data.frame(
      Variables = c("var 1", "var 2", "var 3"),
      Coefficients = c(1.7, 1.2, 2.0),
      Conf.Lower = c(1.4, 0.4, 1.5),
      Conf.Higher = c(2, 2.6, 2.5)
)

data.frame(
      Variable = coef_table$Variables,
      Visualization = ""
) %>%
      kbl(booktabs = T) %>%
      kable_classic(full_width = FALSE) %>%
      column_spec(2, image = spec_pointrange(
            x = coef_table$Coefficients, 
            xmin = coef_table$Conf.Lower, 
            xmax = coef_table$Conf.Higher, 
            vline = 0)) %>% 
      column_spec(2, image = spec_pointrange(
            x = coef_table2$Coefficients, 
            xmin = coef_table2$Conf.Lower, 
            xmax = coef_table2$Conf.Higher, 
            vline = 0))

My objective is that the last column of the table is something like this for var1: enter image description here

0

There are 0 answers