help with mosaic plots
2
0
Entering edit mode
2.6 years ago
peter.berry5 ▴ 60

I'm trying to plot a mosaic style plot using geom_tile of the common GO terms from a DE experiment. As expected each GO term has multiple DE proteins associated with it. I thought I'd plot the GO ID on the x axis and fill each tile with a protein id. But this results in multiple ids being placed in each tile. How can I have a separate tile for each proteins id?

Enriched_GO_ID <- c("GO:0000062", "GO:0000062", "GO:0000062")
Description <- c("fatty-acyl-CoA binding", "fatty-acyl-CoA binding",
                 "fatty-acyl-CoA binding")
Uniprot.ID <- c("P49748", "P49748", "P22307", "P22307", "P13807", "P13807")
Cell.Line <- c("A", "B", "A", "B", "A", "B")
df <- data.frame(Enriched_GO_ID, Description, Uniprot.ID, Cell.Line)

All <- ggplot(df, aes(x = interaction(Enriched_GO_ID, Description ), 
                          y = Cell.Line))+
  geom_tile(color = "white",
            lwd = 2,
            linetype = 1)+ #now have white border between them
  geom_text(aes(label = Uniprot.ID), color = "white", 
            size = 3)+
  scale_fill_fermenter(palette = "Set2", breaks = c(5,2,1.4,0))+
  coord_fixed()+
  labs(title = "",
      y = "Cell Line Name",
      x = "GO Accession ID")+ 
  theme_classic()+ # white background
  theme(axis.text.x = element_text(size = 15, angle = 90),
        axis.text.y = element_text(size = 15),
        axis.title = element_text(size = 20, face = "bold"))
print(All)
dev.off()
plots mosaic R • 1.0k views
ADD COMMENT
0
Entering edit mode
2.6 years ago
gglim ▴ 140

Hi Peter,

This is the output of your code:

your tile

And this is what you want? (don't know if it's correct):

my tile

Inspired by question here.

Hope this is helpful!

ADD COMMENT
0
Entering edit mode

Actually would you mind sharing the code you used? My attempt is below and doesn't give the same result as yours.

df2 <- df %>% 
  group_by(Cell.Line, Enriched_GO_ID) %>%
  mutate(Name1 = paste0(Cell.Line,row_number()))
labs <- with(df2,setNames(as.character(Cell.Line),Name1))
labs2 <- data.frame(labs)

All <- ggplot(df2, aes(x = interaction(Enriched_GO_ID, Description), 
                          y = Name1))+
  geom_tile(color = "white",
            lwd = 2,
            linetype = 1)+ #now have white border between them
  geom_text(aes(label = Uniprot.ID), color = "white", 
            size = 3)+
  scale_fill_fermenter(palette = "Set2", breaks = c(5,2,1.4,0))+
  coord_fixed()+
  scale_y_discrete(labels = df2$Cell.Line)+
  labs(title = "",
      y = "Cell Line Name",
      x = "GO Accession ID")+ 
  theme_classic()+ # white background
  theme(axis.text.x = element_text(size = 15, angle = 90),
        axis.text.y = element_text(size = 15),
        axis.title = element_text(size = 20, face = "bold"))
print(All)

I can't seem to attach the image this generates but the y axis labels in my plot are A, B, A, B, A, B rather than B,B,B,A,A,A. Consequently the protein IDs don't line up with the correct cell line.

ADD REPLY
1
Entering edit mode

Sure thing, here's the code

Enriched_GO_ID <- c("GO:0000062", "GO:0000062", "GO:0000062")
Description <- c("fatty-acyl-CoA binding", "fatty-acyl-CoA binding",
                 "fatty-acyl-CoA binding")
Uniprot.ID <- c("P49748", "P49748", "P22307", "P22307", "P13807", "P13807")
Cell.Line <- c("A", "B", "A", "B", "A", "B")
df <- data.frame(Enriched_GO_ID, Description, Uniprot.ID, Cell.Line)

# Add two lines here
df <- df %>% group_by(Cell.Line) %>% mutate(Name=paste0(Cell.Line,row_number()))
labs <- with(df,setNames(as.character(Cell.Line),Name))

All <- ggplot(df, aes(x = interaction(Enriched_GO_ID, Description ), 
                      y = Name))+ # change the aes y here
  geom_tile(color = "white",
            lwd = 2,
            linetype = 1)+ #now have white border between them
  geom_text(aes(label = Uniprot.ID), color = "white", 
            size = 3)+
  scale_fill_fermenter(palette = "Set2", breaks = c(5,2,1.4,0))+
  coord_fixed()+
  labs(title = "",
       y = "Cell Line Name",
       x = "GO Accession ID")+ 
  theme_classic()+ # white background
  theme(axis.text.x = element_text(size = 15, angle = 90),
        axis.text.y = element_text(size = 15),
        axis.title = element_text(size = 20, face = "bold"))+
  scale_y_discrete(labels=labs) # and a line here

print(All)
ADD REPLY
0
Entering edit mode
2.6 years ago
peter.berry5 ▴ 60

dear ggslim,

That wasn't quite what I had in mind but actually I prefer it to what I was looking for.

Thanks

Peter

ADD COMMENT

Login before adding your answer.

Traffic: 2555 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