Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>See ?stat_summary.</p> <blockquote> <p>fun.data : Complete summary function. Should take data frame as input and return data frame as output</p> </blockquote> <p>Your function <code>max.n.filt</code> uses an <code>if()</code> statement that tries to evaluate the condition <code>x &gt; filter</code>. But when <code>length(x) &gt; 1</code>, the <code>if()</code> statement only evaluates the condition for the first value of <code>x</code>. When used on a data frame, this will return a list cobbled together from the original input <code>x</code> and whatever label the <code>if()</code> statement returns.</p> <pre><code>&gt; max.n.filt(data.frame(x=c(10,15,400))) $y.x [1] 10 15 400 $label [1] "" </code></pre> <p>Try a function that uses <code>ifelse()</code> instead:</p> <pre><code>max.n.filt2 &lt;- function(x){ filter = 300 # whatever threshold y = ifelse( x &gt; filter, max(x) + 1, x[,1] ) label = ifelse( x &gt; filter, round(max(x),2), NA ) return(data.frame(y=y[,1], label=label[,1])) } &gt; max.n.filt2(data.frame(x=c(10,15,400))) y label 1 10 NA 2 15 NA 3 401 400 </code></pre> <p>Alternatively, you might just find it easier to use <code>geom_text()</code>. I can't reproduce your example, but here's a simulated dataset:</p> <pre><code>set.seed(101) sim_data &lt;- expand.grid(m1=1:1440, variable=factor(c(0,0.25,0.5,0.75,1))) sim_data$sample_size &lt;- sapply(1:1440, function(.) sample(1:25, 1, replace=T)) sim_data$value = t(sapply(1:1440, function(.) quantile(rgamma(sim_data$sample_size, 0.9, 0.5),c(0,0.25,0.5,0.75,1))))[1:(1440*5)] </code></pre> <p>Just use the <code>subset</code> argument in <code>geom_text()</code> to select those points you wish to label:</p> <pre><code>ggplot(sim_data, aes(x = m1/60, y = value, color = variable)) + geom_point(size = 4) + geom_text(aes(label=round(value)), subset = .(variable == 1 &amp; value &gt; 25), angle = 90, size = 4, colour = "red", hjust = -0.5) </code></pre> <p>If you have a column of sample sizes, those can be incorporated into <code>label</code> with <code>paste()</code>:</p> <pre><code>ggplot(sim_data, aes(x = m1/60, y = value, color = variable)) + geom_point(size = 4) + geom_text(aes(label=paste(round(value),", N=",sample_size)), subset = .(variable == 1 &amp; value &gt; 25), angle = 90, size = 4, colour = "red", hjust = -0.25) </code></pre> <p>(or create a separate column in your data with whatever labels you want.) If you're asking about <em>how</em> to retrieve the sample sizes, you could modify your call to <code>ddply()</code> like this:</p> <pre><code>... c2 &lt;- ddply(C, .(h1), function (x) { cbind(summarise(x, y = quantile(x$gaps, cuts)), n=nrow(x)) } ) c2$cuts &lt;- cuts c2 &lt;- dcast(c2, h1 + n ~ cuts, value.var = "y") c2.h1.melt &lt;- melt(c2, id.vars = c("h1","n")) ... </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload