title: Highlight Points in Scatterplot w/ ggplot2
body: <p>I need to create a qq plot of -log10 p-values in <code>ggplot2</code> where a subset of 137  points ("targets") are highlighted in gold using a colorblind-friendly palette I'm using called <code>cbbPalette</code>. I <em>cannot</em> do this in an alternate package because I eventually need to combine multiple qq plots into a grid using <code>grid.arrange</code> from the <code>gridExtra</code> package that works with <code>ggplot2</code>. </p>
  
  <p>Setup:</p>
  
  <pre><code>library(ggplot2)
  library(reshape2)
  cbbPalette &lt;- c("#E69F00", "#000000") #part of my palette; gold &amp; black
  set.seed(100)
  </code></pre>
  
  <p>The data consists of 100,137 p-values, 137 of which are targets:</p>
  
  <pre><code>p_values = c(
    runif(100000, min = 0, max = 1),
    runif(132, min = 1e-7, max = 1),
    c(6e-20, 6e-19, 7e-9, 7.5e-9, 4e-8)
  )
  
  #labels for the p-values
  names_letters &lt;-
    do.call(paste0, replicate(2, sample(LETTERS, 100137, TRUE), FALSE))
  names = paste0(names_letters, sprintf("%04d", sample(9999, 100137, TRUE)))
  targets = names[100001:100137] #last 137 are targets
  
  df = as.data.frame(p_values)
  df$names = names
  df &lt;-
    df[sample(nrow(df)), ] #shuffles the df to place targets randomly w/in
  df$Category = ifelse(df$names %in% targets, "Target", "Non-Target")
  </code></pre>
  
  <p>Appearance of Data:</p>
  
  <pre><code>head(df, 4) 
             p_values  names   Category
  89863 0.4821147 NZ3385 Non-Target
  20209 0.3998835 SQ3793 Non-Target
  29200 0.7893478 ZT5497 Non-Target
  71623 0.3459360 QF5311 Non-Target
  </code></pre>
  
  <p>Melted df Using <code>reshape2</code> with Observed (o) &amp; Expected (e) -log10 p-values:</p>
  
  <pre><code>df.m = melt(df)
  df.m$o = -log10(sort(df.m$value, decreasing = F))
  df.m$e = -log10(1:nrow(df.m) / nrow(df.m))
  </code></pre>
  
  <p>Appearance of Melted df:</p>
  
  <pre><code>head(df.m,4)
     names   Category variable     value         o        e
  1 NZ3385 Non-Target p_values 0.4821147 19.221849 5.000595
  2 SQ3793 Non-Target p_values 0.3998835 18.221849 4.699565
  3 ZT5497 Non-Target p_values 0.7893478  8.154902 4.523473
  4 QF5311 Non-Target p_values 0.3459360  8.124939 4.398535
  </code></pre>
  
  <p>QQ-plot</p>
  
  <pre><code>df_qq = ggplot(df.m, aes(e, o)) +
    geom_point(aes(color = Category)) +
    scale_colour_manual(values = cbbPalette) +
    geom_abline(intercept = 0, slope = 1) +
    ylab("Observed -log[10](p)") +
    xlab("Theoretical -log[10](p)")
  </code></pre>
  
  <p>I then get a qq with no highlighting of my 137 targets. </p>
  
  <p><img src="https://i.stack.imgur.com/Uaptc.png" alt="QQ-plot I get w/ no highlighting of 137 targets"></p>