[R] lattice : superpose symbols with a great many points

Laurent Rhelp LaurentRHelp at free.fr
Sun Jun 22 23:09:42 CEST 2014


Le 20/06/2014 21:50, Christoph Scherber a écrit :
> Dear Laurent
>
> for numeric x variables, you could try jitter:
>
> xyplot(y~jitter(x,0.5))
>
> Cheers
> Christoph
>
>
> Am 20.06.2014 21:45, schrieb Laurent Rhelp:
>> Hi,
>>
>>   I like to use with xyplot (package lattice) the groups argument and 
>> superpose.symbol to compare several curves. But, when there are a 
>> great many points, the symbols are very close and the graph becomes 
>> unreadable. Would there be an argument  or a tip not to draw all the 
>> symbols, for example the symbols could be drawn only every x points, 
>> x given as an argument ?
>>
>> Thanks
>> Best regards
>> Laurent
>>
>>
>>
>> ---
>> Ce courrier électronique ne contient aucun virus ou logiciel 
>> malveillant parce que la protection avast! Antivirus est active.
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> 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.
>
> ______________________________________________
> R-help at r-project.org mailing list
> 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.
>
It is a very good idea !!! The symbols become readable but it is not an 
actual answer to the issue.

I finally wrote the code below which works but I think there is 
certainly something easier (shorter) !!!

Thanks

--o<----------------------------------------------------------------------------------------->o----
##
## 1. mock data
##
n <- 10000
time <- seq(-10*pi,10*pi,length=n)
essai <- c("essai1","essai2","essai3","essai4","essai5")

ll <- list()
for( i in 1:5){
    ll[[i]] <-data.frame(time=time,
                         value=sin(time+(pi/i)),
                         essai=essai[i])
}
data.sim <- do.call("rbind",ll)
##
## 2. lattice initialisation for the colors and the symbols
##
para.liste <- trellis.par.get()
superpose.symbol <- para.liste$superpose.symbol
superpose.symbol$pch <- seq(1,5)
superpose.symbol$col <- seq(1,5)
##
## 3. lattice code
##
xyplot(value ~ time,
        data=data.sim,
        nr=100,
        groups=essai,

        panel = function(x,y,subscripts,groups,nr,...) {
                        panel.abline(v=0, lty = "dotted", col = "black")
                        groupsnames <- levels(groups)
                        ng <- length(groupsnames)
                        for( i in 1:ng){
                             g <- groupsnames[i]
                             idg <- g == groups[subscripts]
                             superpose.symbol <- 
trellis.par.get("superpose.symbol")
                             ncol <- superpose.symbol$col[i]
                             npch <- superpose.symbol$pch[i]

                             ## we draw only the line
panel.xyplot(x[idg],y[idg],type="l",col=ncol,...)

                             ## and then we draw a symbol every nr points
                             idx <- seq(1,length(x[idg]),by=nr)
                             idy <- seq(1,length(y[idg]),by=nr)
panel.points(x[idg][idx],y[idg][idy],col=ncol,pch=npch)
                         }
             },
        par.settings = list(
             superpose.symbol=superpose.symbol
            )
     )

--o<--------------------------------------------------------------------------------------->o----







---
Ce courrier électronique ne contient aucun virus ou logiciel malveillant parce que la protection avast! Antivirus est active.



More information about the R-help mailing list