[R] tip: large plots

Hadley Wickham hadley at rice.edu
Fri Nov 18 21:39:24 CET 2011


You need: system.time(print(qplot(x,y,pch=I('.'))))

Hadley

On Fri, Nov 18, 2011 at 1:30 PM, Justin Haynes <jtor14 at gmail.com> wrote:
> Very cool.  Sadly, as far as I can tell, it doesn't work with ggplot though
> :(
>
>
>> x<-runif(1e6)
>> y<-runif(1e6)
>> system.time(plot(x,y,pch='.'))
>   user  system elapsed
>  0.824   0.012   0.845
>> system.time(plot(x,y))
>   user  system elapsed
>  33.422   0.016  33.545
>> system.time(print(qplot(x,y)))
>   user  system elapsed
>  45.142   0.228  45.687
>> system.time(print(qplot(x,y,pch='.')))
>   user  system elapsed
>  47.483   1.060  49.040
>> system.time(print(qplot(x,y,shape='.')))
>   user  system elapsed
>  44.807   0.689  45.710
>
>
> On Fri, Nov 18, 2011 at 11:03 AM, Sarah Goslee <sarah.goslee at gmail.com>wrote:
>
>> Hi all,
>>
>> I'm working with a bunch of large graphs, and stumbled across
>> something useful. Probably many of you know this, but I didn't and so
>> others might benefit.
>>
>> Using pch="." speeds up plotting considerably over using symbols.
>>
>> > x <- runif(1000000)
>> > y <- runif(1000000)
>> > system.time(plot(x, y, pch="."))
>>   user  system elapsed
>>  1.042   0.030   1.077
>> > system.time(plot(x, y))
>>   user  system elapsed
>>  37.865   0.033  38.122
>>
>> If you have enough points, the result is also more legible.
>>
>> Choice of which pch symbol makes a difference too, the default pch=1 being
>> the slowest of what I tried, but "." is by far the speediest.
>>
>> > system.time(plot(x, y, pch=0))
>>   user  system elapsed
>>  11.191   0.011  11.270
>> > system.time(plot(x, y, pch=1))
>>   user  system elapsed
>>  38.024   0.008  38.245
>> > system.time(plot(x, y, pch=2))
>>   user  system elapsed
>>  14.140   0.027  14.270
>> > system.time(plot(x, y, pch=3))
>>   user  system elapsed
>>  15.696   0.011  15.799
>> > system.time(plot(x, y, pch=4))
>>   user  system elapsed
>>  18.770   0.007  18.888
>>
>> This is a vanilla R session, 2.13.1 for x86_64-redhat-linux-gnu. I
>> haven't tried it on any other OS, but it's making my life a lot
>> smoother right now.
>>
>> Sarah
>>
>> --
>> Sarah Goslee
>> http://www.functionaldiversity.org
>>
>> ______________________________________________
>> 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.
>>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>



-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/



More information about the R-help mailing list