Answers.Body: <p>I'm not sure that boxplot will be the more appropriate representation, as you will end with two numbers (count of Clonal and SubClonal) per groups of patients.</p>
  
  <p>One solution will be to first create a new categorical variable based on CCF values using for example <code>ifelse</code> statement for example by writing:</p>
  
  <pre class="lang-r prettyprint-override"><code>df$Clonal &lt;- ifelse(df$CCF &gt; 0.95,"Clone","SubClonal")
  </code></pre>
  
  <p>Then you can get the count of each Clone and subclone for each responders and non responders by using <code>table</code>: </p>
  
  <pre class="lang-r prettyprint-override"><code>DF &lt;- as.data.frame(table(df[,c("Response","Clonal")]))
  </code></pre>
  
  <p>You can finally convert these new values as percentage by grouping according to the Response. For example, using <code>dplyr</code>, you can do something like that:</p>
  
  <pre class="lang-r prettyprint-override"><code>library(dplyr)
  
  DF %&gt;% group_by(Response) %&gt;% mutate(Freq_percent = Freq / sum(Freq))
  </code></pre>
  
  <p>And finally, you can plot it as a barchart or single point in <code>ggplot2</code>.
  Hope it helps you to figure it out how to deal with your data. </p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-04T03:43:50.257Z
Answers.LastActivityDate: 2020-04-04T03:43:50.257Z
Answers.UserDisplayName: dc37
Body: <p>I have 2 groups of patients; responders to chemotherapy and non-responders</p>
  
  <p>I have calculated cancer cell fraction (CCF) of a set of driver genes (by variant allele frequency) for each group and I have </p>
  
  <pre><code>&gt; head(dat)
      Response       CCF
  1 Responders 1.0000000
  2 Responders 0.5413323
  3 Responders 1.0000000
  4 Responders 1.0000000
  5 Responders 1.0000000
  6 Responders 1.0000000
  
  unique(dat$Response)
  
  
  [1] Responders    Nonresponders
  Levels: Nonresponders Responders
  &gt; 
  </code></pre>
  
  <p>If CCF > 0.95 , the mutation is clonal otherwise sub clonal</p>
  
  <p>I want to show how many clone and subclone are in these two groups by box plot or something similar like below</p>
  
  <p><a href="https://i.sstatic.net/Q3smM.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Q3smM.png" alt="enter image description here"></a></p>
  
  <p>I have tried this which was nonsense </p>
  
  <pre><code>ggplot(dat, aes(x=Response, y=CCF)) + 
      geom_boxplot()
  </code></pre>
  
  <p>Can you help me?</p>
  
Tags: <r><ggplot2><software-usage>
Title: A box plot of qualitative variables
ThreadText: # A box plot of qualitative variables
  
  (Asked by: username_0 on 2020-04-04)
  
  I have 2 groups of patients; responders to chemotherapy and non-responders
  
  I have calculated cancer cell fraction (CCF) of a set of driver genes (by variant allele frequency) for each group and I have
  
  ```
  > head(dat)
      Response       CCF
  1 Responders 1.0000000
  2 Responders 0.5413323
  3 Responders 1.0000000
  4 Responders 1.0000000
  5 Responders 1.0000000
  6 Responders 1.0000000
  
  unique(dat$Response)
  
  [1] Responders    Nonresponders
  Levels: Nonresponders Responders
  > 
  
  ```
  
  If CCF > 0.95 , the mutation is clonal otherwise sub clonal
  
  I want to show how many clone and subclone are in these two groups by box plot or something similar like below
  
  [![enter image description here](https://i.sstatic.net/Q3smM.png)](https://i.sstatic.net/Q3smM.png)
  
  I have tried this which was nonsense
  
  ```
  ggplot(dat, aes(x=Response, y=CCF)) + 
      geom_boxplot()
  
  ```
  
  Can you help me?
  
  **Tags:** r, ggplot2, software-usage
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-04-04. Score: 1 | Accepted answer
  
  I'm not sure that boxplot will be the more appropriate representation, as you will end with two numbers (count of Clonal and SubClonal) per groups of patients.
  
  One solution will be to first create a new categorical variable based on CCF values using for example `ifelse` statement for example by writing:
  
  ```r
  df$Clonal <- ifelse(df$CCF > 0.95,"Clone","SubClonal")
  
  ```
  
  Then you can get the count of each Clone and subclone for each responders and non responders by using `table`:
  
  ```r
  DF <- as.data.frame(table(df[,c("Response","Clonal")]))
  
  ```
  
  You can finally convert these new values as percentage by grouping according to the Response. For example, using `dplyr`, you can do something like that:
  
  ```r
  library(dplyr)
  
  DF %>% group_by(Response) %>% mutate(Freq_percent = Freq / sum(Freq))
  
  ```
  
  And finally, you can plot it as a barchart or single point in `ggplot2`.
  Hope it helps you to figure it out how to deal with your data.
  
  
  ---
  
  