how do I add a title to an Upset plots
1
1
Entering edit mode
3.4 years ago
peter.berry5 ▴ 60

I was trying to add a title to an upset plot using the suggestion in this post but it returned an error.

Error in upset(plot, nintersects = 8, nsets = 6, sets = c("Pos.Corr.K1",  : 

non-numeric argument to binary operator

My code is

library (Upset)
library(grid)
#setting up some random data
Pos.Corr.K1 <- c("GO:0055114", "GO:0016491", 
                        "GO:0016620", "GO:0005739", 
                        "GO:0005759", "GO:0022900", 
                        "GO:0016208")

Neg.Corr.K1 <- c("GO:0005840", "GO:0003987", 
                        "GO:0019427", "GO:0005524",
                        "GO:0005737", "GO:0043231", 
                        "GO:0000166")

Pos.Corr.DXB11 <- c("GO:0055114", "GO:0016491", 
                           "GO:0005739", "GO:0005737", 
                           "GO:0043231", "GO:0000166", 
                           "GO:0005524")

Neg.Corr.DXB11 <- c("GO:0016620", "GO:0005759", 
                           "GO:0022900", "GO:0005840", 
                           "GO:0003987") 

#Draw Upset Plot
data <- list( Pos.Corr.K1, Neg.Corr.K1,  
             Pos.Corr.DXB11, Neg.Corr.DXB11)
names(data) <- c( "Pos.Corr.K1", "Neg.Corr.K1", 
                  "Pos.Corr.DXB11", 
                 "Neg.Corr.DXB11") 
plot <- UpSetR::fromList(data) 
setwd("C:/PETER PROJECT/3g. Mass Spec Processing (Comparison of K1 v DXB11)/Results/Upset Plot")
# create PNG for the heat map     
png("Upset Plot (2) - K1 v DXB11 (DE Proteins).png",   
width = 10*300,        # 10 x 300 pixels
height = 10*300,
res = 300,)            # 300 pixels per inch
Upset <- upset(plot, 
          nintersects = 8, 
          nsets = 6,
          sets = c( "Pos.Corr.K1", "Neg.Corr.K1", 
                  "Pos.Corr.DXB11", "Neg.Corr.DXB11"),
          #group.by = "sets", 
          #cutoff = 0,
          empty.intersections = "off",
          order.by = "freq", 
          decreasing = T, 
          point.size = 5,
          line.size = 1,
          mb.ratio = c(0.65, 0.35),
          number.angles = 0, 
          text.scale = c(2, 2, 2, 2, 2, 2) 
          #text.scale = c(intersection size title, 
          #               intersection size tick labels, set size title, 
          #               set size tick labels, set names, 
          #               numbers above bars)
          ) +
grid.text("Distribution of DE Proteins", x = 0.65, y = 0.95,
          gp = gpar(fontsize = 20))
print(Upset)

The code runs perfectly without the lines

+
    grid.text("Distribution of DE Proteins", x = 0.65, y = 0.95,
              gp = gpar(fontsize = 20))

but this is the code suggested in the original post.

Any advice would be appreciated.

Upset plots R • 5.3k views
ADD COMMENT
2
Entering edit mode
3.4 years ago
seidel 11k

If you run upset() on its own, and run grid.text() afterwards, you get a plot with a title (I do, using your code). Too bad upset doesn't take a title argument - apparently one might be available in UpSetR_1.4.1.

Anyway, you can draw your plot and then you should be able to use dev.copy2pdf() or given your current set up: dev.off() to create the figure.

You also have an extra comma in your png() function call.

ADD COMMENT

Login before adding your answer.

Traffic: 1849 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6