2
$\begingroup$

I'm taking data from cbioportal of gene and their mutation frequency with percentage which I'm trying to categorize with various sub class.

The issue I'm facing is I have to plot it in mutation frequency which are already given. I'm not sure how to go about it.

This is my code (I'm attaching the data), but what I'm missing is the frequency count of patients. As an example NPM1 altered in 50 patient with 31.00% where the number of patient is 162, I'm going for stacked bar plot, as the frequency is already given, how can I just plot in terms of frequency ?

data

df.m1 <- reshape2::melt(ALL_NEW_RBP, id.vars = NULL)


library(dplyr)
d3 <- df.m1 %>% 
  group_by(variable,value) %>% 
  summarise(count=n()) %>% 
  mutate(perc=count/sum(count))

colnames(d3) <- c("variable","value","count","percentage")

cbPalette <- c("black","darkblue","brown4","darkred","darkslategrey","deeppink","orange4","mediumorchid1","lightpink",
               "khaki1","gray70","cyan","coral1")


ggplot(d3, aes(x = factor(variable), y = percentage*100, 
          fill = factor(d3$value,levels = c("3 ","4","5","6","7","8","9","10","11","12","13","31","NA","0")))) +
  scale_fill_manual(values = cbPalette, na.value = "lightsteelblue") +
  geom_bar(stat="identity", width = 0.7) +
  labs(x = "Categories", y = "percent alteration", fill = "Percentage") +
  theme_bw(base_size=15)+

  theme(axis.text.x=element_text(angle = 45, size=25, face="bold", hjust = 1), 
        axis.text.y=element_text(angle=0, size=35, face="bold", vjust=0.5),
        plot.title = element_text(size=40, face="bold"), 
        legend.title=element_blank(), 
        legend.key.size=unit(1, "cm"),      #Sets overall area/size of the legend
        legend.text=element_text(size=30))

barplot

$\endgroup$
  • $\begingroup$ Could you attach the resulting image? Also, I think this question is more about how to use ggplot2 than about bioinformatics, you probably will have more answers if you post it on StackOverflow $\endgroup$ – llrs Nov 27 '18 at 10:18
  • $\begingroup$ added the figure..where the legend suggest the percentage of mutation you can have a look at the data and let know $\endgroup$ – krushnach Chandra Nov 27 '18 at 10:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.