<font face="trebuchet ms,sans-serif">Samuel, tente adaptar isso aqui<br><br><span style="font-family:courier new,monospace">set.seed(123)</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">x <- rnorm(1000, 5, 2)</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">plot(density(x))</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">breaks <- sort(c(range(x), quantile(x, c(1,3)/4)))</span><br style="font-family:courier new,monospace">
<br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">dx <- density(x)</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">fx <- approxfun(dx$x, dx$y)</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">fx(0.5)</span><br style="font-family:courier new,monospace"><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">do.polygon <- function(x){</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> y <- fx(x)</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> return(list(x=c(min(x), x, max(x)), y=c(0, y, 0)))</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">}</span><br style="font-family:courier new,monospace"><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">seqs <- lapply(1:(length(breaks)-1),</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> function(i){</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> x <- seq(breaks[i], breaks[i+1], l=30)</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> do.polygon(x)</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> })</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">str(seqs)</span><br style="font-family:courier new,monospace"><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">plot(density(x))</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">polygon(seqs[[1]], density=2)</span><br style="font-family:courier new,monospace"><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">seqs[[1]]$density <- 3</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">seqs[[2]]$density <- 5</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">seqs[[3]]$density <- 9</span><br style="font-family:courier new,monospace">
<br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">plot(density(x))</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">lapply(seqs, function(i) do.call(polygon, i))</span><br style="font-family:courier new,monospace">
<br style="font-family:courier new,monospace">À disposição.<span class="HOEnZb"><font color="#888888"><br>Walmes.<br></font></span></font>