title: visualizing statistical test results with ggplot2
body: <p>I would like to get my statistical test results integrated to my plot. Example of my script with dummy variables (dummy data below generated after first post): </p>
  
  <pre><code>cases &lt;- rep(1:1:5,times=10)
  var1 &lt;- rep(11:15,times=10)
  outcome &lt;- rep(c(1,1,1,2,2),times=10)
  
  maindata &lt;- data.frame(cases,var1,outcome)
  
  df1 &lt;- maindata %&gt;%
    group_by(cases) %&gt;%
    select(cases,var1,outcome) %&gt;%
    summarise(var1 = max(var1, na.rm = TRUE), outcome=mean(outcome, na.rm =TRUE))
  
  wilcox.test(df1$var1[df1$outcome&lt;=1], df1$var1[df1$outcome&gt;1])
  
  ggplot(df1, aes(x = as.factor(outcome), y = as.numeric(var1), fill=outcome)) + geom_boxplot()
  </code></pre>
  
  <p>With these everything works just fine, but I can't find a way to integrate my wilcox.test results to my plot automatically (of course I can make use annotation() and write the results manually but that's not what I'm after. </p>
  
  <p>My script produces two boxplots with max-value of var1 on the y-axis and grouped by outcome on the x-axis (only two different values for outcome). I would like to add my wilcox.test results to that boxplot, all other relevant data is present. Tried to find a way from forums and help files but can't find a way (at least with ggplot2) </p>
  
  <p>I'm new to R and trying learn stuff through using ggplot2 and dplyr which I see as most intuitive packages for manipulation and visualization. Don't know if they are optimal for the solution which I'm after so feel free to suggest solutions from alternative packages also...</p>