rupsetrupsetplot

Changing set name labels


I can see that this has been asked several times before, but I can no find a method that works. Are there any clever people out there that can figure this out?

    data.frame(
    fast_car = sample(0:1, 35, replace = TRUE),
    slow_bus = sample(0:1, 35, replace = TRUE),
    fast_bus = sample(0:1, 35, replace = TRUE),
    slow_car = sample(0:1, 35, replace = TRUE)) %>% 
  upset(order.by = "freq")

This makes a very nice upset graph but I need to get rid of the the underscore in the set labels. I tried the answer suggested in this post: UpsetR change set name labels in graph

fast_car <- as.list(sample(0:1, 35, replace = TRUE))
slow_bus <- as.list(sample(0:1, 35, replace = TRUE))
fast_bus <- as.list(sample(0:1, 35, replace = TRUE))
slow_car <-  as.list(sample(0:1, 35, replace = TRUE))

listinput = list(fast_bus, fast_car, slow_bus, slow_car)
names(listinput) = c("fast bus", "fast car", "slow_bus", "slow car")
upset(fromList(listinput), order.by = "freq")

However this results in nice labels but the graph doesn't come out correctly. I have also tried usuing a tibble with labeled columns but the package doesnt seem to work with the tibble.

Is there a way of doing this? I would just use one word but it really needs 2 word labels.

Any help would be greatly appreciated, if a solution indeed exists?

Many thanks!


Solution

  • Generally "non-standard" column names should be avoided, but this might be an exception. You can use spaces and other special characters in column names if you quote them or surround them in backticks (and make sure they don't get autocorrected).

    A couple options:

    ## creating the data frame with nonstandard names
    data.frame(`fast car` = c(0, 1), check.names = FALSE)
    
    ## modifying names of an existing data frame
    your_data %>% 
      setNames(c("fast car", "slow bus", "fast bus", "slow car") %>% 
      upset(order.by = "freq")