GEOM Tile adjustments

Hi everybody,

Thank you very much in advance for looking through this question! Been very impressed with how well everyone has been able to answer my questions in the past, and thought that you all may be my best hope at making a few adjustments to a geom_tile chart that I've made.

Effectively, what we have are a few columns of metrics and a few rows of categories. The top row is an "overall" row, and the one that we care the most about in this case. The next step that has been requested would be to make the gap between the OVERALL row and the others wider (to emphasize the distinction), and then to add some sort of line between that overall row and the others.

Abstractly speaking (I know I haven't put in any of the code here to review), is anyone aware of ways that this could be accomplished?


I hope this is of some help:

cats <- c('ABC', 'DEF', 'GHI')
tbl <- crossing(catn = c(1,2,3),
                met = c('Approved Volume',
                        'Approved Exposure',
                        'Approval Rate')) %>%
       mutate(value = runif(9), cat = cats[catn])
my_height <- 0.95
my_width <- 0.95
extra <- 0.2
max_catn <- max(tbl$catn) + 1 + extra

TBL <- bind_rows(tbl,
                 tbl %>% group_by(met) %>%
                         summarise(value = sum(value)) %>%
                         ungroup %>%
                         mutate(catn = max_catn,
                                cat = 'Overall') %>%
                         select(catn, cat, met, value))

y_info <- TBL %>% select(catn, cat) %>% distinct %>% arrange(catn)

TBL <- TBL %>% mutate(met = factor(met, levels =  c('Approved Volume',
                                                    'Approved Exposure',
                                                    'Approval Rate')))

pp <- ggplot(TBL) +
          geom_tile(aes(x = met,
                        y = catn,
                        fill = value),
                    height = my_height,
                    width =my_width) +
          geom_hline(yintercept = max_catn - 0.5 - (extra/2),
                     colour='red') +
          theme_bw() +
          scale_y_continuous(breaks = y_info$catn, labels = y_info$cat) +
          scale_x_discrete(position = 'top') +
          labs(x = '', y = '') +
          theme(axis.text.y = element_text(angle = 90, hjust = 0.5))

Created on 2019-07-12 by the reprex package (v0.2.1)


That looks really promising! I'll be sure to give this a shot, thank you!