[R] ggplot2: discontinuous ribbon

sbihorel Sebastien.Bihorel at cognigencorp.com
Wed Oct 21 11:31:10 CEST 2015


Thanks!

On 10/21/2015 5:25 AM, Thierry Onkelinx wrote:
> Dear Sebastien,
>
> You are looking for geom_polygon().
>
> Best regards,
>
> ir. Thierry Onkelinx
> Instituut voor natuur- en bosonderzoek / Research Institute for Nature 
> and Forest
> team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
> Kliniekstraat 25
> 1070 Anderlecht
> Belgium
>
> To call in the statistician after the experiment is done may be no 
> more than asking him to perform a post-mortem examination: he may be 
> able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher
> The plural of anecdote is not data. ~ Roger Brinner
> The combination of some data and an aching desire for an answer does 
> not ensure that a reasonable answer can be extracted from a given body 
> of data. ~ John Tukey
>
> 2015-10-21 11:20 GMT+02:00 sbihorel 
> <Sebastien.Bihorel at cognigencorp.com 
> <mailto:Sebastien.Bihorel at cognigencorp.com>>:
>
>     Hi
>
>     I would like to use ggplot2 to create a 2d plot showing a series
>     of shaded areas that are not continuous with respect to the x-axis
>     variable. The expected result is illustrated below using
>     lattice/grid functions.
>
>     -------------
>     pdata <- data.frame(
>       x=c(1,2,2,1,NA,3,4,4,3,NA,5,6,6,5),
>       y=c(3,3,2,2,NA,2,2,1,1,NA,2.5,3,2,2))
>
>     lattice::xyplot((1:6)~(1:6),panel=function(pdata=pdata){
>       grid::grid.polygon(pdata$x,pdata$y,
>                    default.units='native',
>                    gp=grid::gpar(fill=1,col=NULL,lty=0))
>     },pdata=pdata)
>     -------------
>
>     Here is my attempt to reproduce this plot in ggplot.
>
>     -------------
>     library(ggplot2)
>     data <- data.frame(
>       x=c(1,2,NA,3,4,NA,5,6),
>       ymin=c(2,2,NA,1,1,NA,2,2),
>       ymax=c(3,3,NA,2,2,NA,2.5,3)
>     )
>
>     ggplot(data,aes(x=x))+geom_ribbon(aes(ymin=ymin,ymax=ymax))
>     -------------
>
>     Obviously, either geom_ribbon expects continuity in the data or I
>     need to setup my data and/or call differently...
>
>     Thanks for your help
>
>     Sebastien
>
>     ______________________________________________
>     R-help at r-project.org <mailto:R-help at r-project.org> mailing list --
>     To UNSUBSCRIBE and more, see
>     https://stat.ethz.ch/mailman/listinfo/r-help
>     PLEASE do read the posting guide
>     http://www.R-project.org/posting-guide.html
>     and provide commented, minimal, self-contained, reproducible code.
>
>



More information about the R-help mailing list