Please have a look at the example provided:
data <- reshape2::melt(Titanic)
data2 <- gather_set_data(data, 1:4)
ggplot(data2, 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')
(I added the data2 to differentiate the datasets and see the result of the transformation:
What you did wrong:
- The " gather_set_data(name_data)" should not use all columns but just the categories
- The ggplot function then uses the modified data, not the initial data set ( name_data).
- Your input doesn't contain any counts that can be shown (no value column)
name_data <- data.frame(
"City" = c("Paris", "Paris", "Paris", "Paris", "Paris", "London", "London", "London", "Paris", "London", "Paris"),
"First_Name" = c("John", "John", "John", "John", "John", "John", "James", "James", "Adam", "Adam", "Henry"),
"Middle_Name" = c("Claude", "Claude", "Claude", "Smith", "Smith", "Peters", "Stevens", "Stevens", "Ford", "Tom", "Frank"),
"Last_Name" = c("Tony", "Tony", "Frank", "Carson", "Phil", "Lewis", "Eric", "David", "Roberts", "Scott", "Xavier"),
"value" = round(runif(11, 0, 12),0)
)
data <- reshape2::melt(name_data)
data2 <- gather_set_data(name_data, 2:4) # I use 2:4 to leave city out from the plot
ggplot2::ggplot(data2, aes(x, id = id, split = y, value = value)) +
geom_parallel_sets(aes(fill = City),
alpha = 0.3, axis.width = 0.1) +
geom_parallel_sets_axes(axis.width = 0.1) +
geom_parallel_sets_labels(colour = 'white')