PharmGirl
PharmGirl

Reputation: 61

UpsetR change set name labels in graph

I am trying to change the set name labels in my UpsetR plot (using Upset function) to be a string of multiple words. Instead of 'A', 'B', 'C' as the set labels I want to have the set labels appear as 'A Description', 'B Description', 'C Description'. I do not want periods or underscores between the words.

test <- upset(grouped_hot,
sets= c("A Description", "B Description","C Description", "N Description"),
nintersects = 8, 
mb.ratio = c(0.6, 0.4),
sets.x.label = "Number of Patients",
sets.bar.color =  "#56B4E9", 
mainbar.y.label = "Number of Patients",
order.by = "freq", 
empty.intersections = "on", 
keep.order = FALSE,
 scale.sets = "identity", 
att.pos = "top", 
text.scale = c(2.5,2.5,2,1.5,2.5,2.5))

The actual result is that my sets on my image are labeled A.Description, B.Description and C.Description. However, I do not want the periods between the words and instead want a space. Any ideas to change the names of the Set Name Labels just for the purposes of the plot? Thank you!

Upvotes: 3

Views: 2833

Answers (2)

Pierre-louis Stenger
Pierre-louis Stenger

Reputation: 301

As I work with data.frame, Ana's answer did not work for me.

But in the same vein, changing the column names at the last moment only for the UpSet plot works very well for changing the labels:

names(data.frame)[names(data.frame) == 'old_name_01'] <- 'New_name_1'
names(data.frame)[names(data.frame) == 'old_name_02'] <- 'New_name_2'
names(data.frame)[names(data.frame) == 'old_name_03'] <- 'New_name_3'

upset(data.frame, sets = c("New_name_1", "New_name_2", "New_name_3"
), sets.bar.color = c("chocolate1", "chocolate2", "chocolate3"),
order.by = "freq", empty.intersections = "on")

Upvotes: 1

Ana
Ana

Reputation: 97

I am using upset function in slighlty different way, but then it might help you if you are able to reformat/reorder your input data.

Here:

##make input list
listInput = list(data.list1,
                 data.list2,
                 data.list3)
##rename list
names(listInput) = c("Name 1", "Name 2", "Name 3")

#make diagram
upset(fromList(listInput), order.by = "freq", #input, descending order  
      mainbar.y.label = "Number of common genes", #y axis
      sets.x.label = "Number of genes \nin the dataset", #x axis small plot
      main.bar.color = "black",
      sets.bar.color = "black",
      mainbar.y.max = 10 #y axis adjustment
        )

It reads set names as Name 1, Name 2, and Name 3.

Hope it helps :) Ana

Upvotes: 2

Related Questions