Body: <p>I'm taking data from cbioportal of gene and their mutation frequency with percentage which I'm trying to categorize with various sub class.</p>
  
  <p>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.</p>
  
  <p>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 ?</p>
  
  <p><a href="https://drive.google.com/open?id=1k8uIQ5hKHyMoMJB8V0Hdc1F17aD5T2s8" rel="nofollow noreferrer">data</a></p>
  
  <pre><code>df.m1 &lt;- reshape2::melt(ALL_NEW_RBP, id.vars = NULL)
  
  
  library(dplyr)
  d3 &lt;- df.m1 %&gt;% 
    group_by(variable,value) %&gt;% 
    summarise(count=n()) %&gt;% 
    mutate(perc=count/sum(count))
  
  colnames(d3) &lt;- c("variable","value","count","percentage")
  
  cbPalette &lt;- 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))
  </code></pre>
  
  <p><a href="https://i.sstatic.net/Fq6l2.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Fq6l2.jpg" alt="barplot"></a></p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-11-27T10:18:44.697Z
Comments.Text: 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
Comments.UserDisplayName: llrs
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-11-27T10:33:31.023Z
Comments.Text: added the figure..where the legend suggest the percentage of mutation you can have a look at the data and let know
Comments.UserDisplayName: kcm
Tags: <r><ggplot2>
Title: How to plot gene mutation frequencey in terms of percnatge alteration in samples?
ThreadText: # How to plot gene mutation frequencey in terms of percnatge alteration in samples?
  
  (Asked by: username_0 on 2018-11-27)
  
  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](https://drive.google.com/open?id=1k8uIQ5hKHyMoMJB8V0Hdc1F17aD5T2s8)
  
  ```
  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](https://i.sstatic.net/Fq6l2.jpg)](https://i.sstatic.net/Fq6l2.jpg)
  
  **Tags:** r, ggplot2
  
  > **Comments:**
  > **username_1**: 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  
  > **username_0**: added the figure..where the legend suggest the percentage of mutation you can have a look at the data and let know  
  
  ---
  
  ## 0 answers
  
  