davidsjoberg/ggsankey

How to center node labels within its legend shape and with the node

Opened this issue · 0 comments

Hi there,

I just create a Sankey diagram and everything worked well. I wan to center the text inside the gray boxes of each node and to put them under the node but centered to it. Is it possible? I left here what I have:

df_sankey <- acumulador3 %>% make_long(unificador,  es_codif, VARIANT_CLASS, existing_dico, Consequence, sigclinico )
  
dagg <- df_sankey%>%
    dplyr::group_by(node)%>%
    tally()

df_sankey2 <- merge(df_sankey, dagg, by.x = 'node', by.y = 'node', all.x = TRUE)

sankey_plot2 <- ggplot(df_sankey2, aes(x = x, next_x = next_x,  node = node ,
                                         next_node = next_node, fill = factor(node),
                                         label = paste(node,'\n'," n=", n))) +
    geom_sankey(flow.alpha=0.5, show.legend = T) + 
    geom_sankey_label(size = 3, fill='gray80', hjust = -0.1) + 
    scale_x_discrete(labels=c('Total Variants', 'Type of variant', 'nonCoding/Coding',
                              'Novel/Existing','Consequence', 'sigclinico')) +
    scale_fill_viridis_d()+
    theme_sankey(base_size = 12) +
    theme(legend.position = "none",
          axis.title.x = element_blank())

IMAGE:
image