Home > database >  In `ggforce/geom_parallel_sets_labels`, how to add more information to the bar label
In `ggforce/geom_parallel_sets_labels`, how to add more information to the bar label

Time:11-02

In ggforce/geom_parallel_sets_labels , how to add the person count number to the black bar ? Thanks! (Below code use data Titanic, and want to show person count number in the bar )

library(tidyverse)
library(ggforce)

data <- reshape2::melt(Titanic)
data <- gather_set_data(data, 1:4)

ggplot(data, aes(x, id = id, split = y, value = value))  
  geom_parallel_sets(aes(fill = Sex), alpha = 0.3, axis.width = 0.1)  
  geom_parallel_sets_axes(axis.width = 0.1)  
  geom_parallel_sets_labels(colour = 'white')

CodePudding user response:

You could use after_stat to alter the default label and add e.g. the counts from the value column like so:

library(tidyverse)
library(ggforce)

data <- reshape2::melt(Titanic)
data <- gather_set_data(data, 1:4)

ggplot(data, aes(x, id = id, split = y, value = value))  
  geom_parallel_sets(aes(fill = Sex), axis.width = 0.3, alpha = 0.3)  
  geom_parallel_sets_axes(axis.width = 0.3)  
  geom_parallel_sets_labels(aes(label = after_stat(paste(label, value, sep = "\n"))), colour = 'white')

  • Related