Speeding up ggplot2

214 views
Skip to first unread message

Jeroen

unread,
Aug 12, 2009, 3:48:01 PM8/12/09
to ggplot2
I am using ggplot2 in a web application. However, I noticed that on
some servers, the printing of a ggplot can take quite long, which is a
problem for web applications. Ironically, my server with the best
hardware, which usually outperforms all others, performs very bad for
printing ggplots.

I made a little script to test the performance on several servers. It
is attached at the bottom of this message. On my cheap and small
server, the average 'elapsed' time for plotting this graph is about
1.1 sec. However, on my fast server, it is about 3.0 seconds. Both
servers run CentOS 5.3, and R 2.9.1-1. Is there anything I can change
in the server config to speed up the plotting of graphs?


### Testing Script starts here ###

library(ggplot2);
myData <- read.csv("http://ichart.finance.yahoo.com/table.csv?
s=GOOG&d=7&e=11&f=2009&g=d&a=7&b=19&c=2004&ignore=.csv",header=T);
myData$Date <- as.Date(myData$Date);

test <- function(){
pdf("test.pdf")
myPlot <- qplot(Date,Close,data=myData,geom=c('line','smooth'));
print(myPlot);
dev.off();
}

for(i in 1:10){
print(system.time(test()));
}

Jeroen

unread,
Aug 12, 2009, 3:54:46 PM8/12/09
to ggplot2
The url in the script was too long for an email, so I replaced it with
a tiny url. This script should work directly:

### Testing Script starts here ###

library(ggplot2);
myData <- read.csv("http://tinyurl.com/krxxpl",header=T);
myData$Date <- as.Date(myData$Date);

test <- function(){
pdf("test.pdf")
myPlot <- qplot(Date,Close,data=myData,geom=c
('line','smooth'));
print(myPlot);
dev.off();
}

for(i in 1:10){
print(system.time(test()));
}

### Script ends here ###

Winston Chang

unread,
Aug 13, 2009, 11:16:20 AM8/13/09
to Jeroen, ggplot2
I agree that it would be nice to speed up ggplot2 -- running a script that generates around 5 plots on my netbook can take a few minutes, and this slows down the process of data exploration.


Would a significant speedup of ggplot2 require rewriting large portions of the code in C?

-Winston

hadley wickham

unread,
Aug 13, 2009, 1:03:34 PM8/13/09
to Winston Chang, Jeroen, ggplot2
> I agree that it would be nice to speed up ggplot2 -- running a script that
> generates around 5 plots on my netbook can take a few minutes, and this
> slows down the process of data exploration.
>
> Would a significant speedup of ggplot2 require rewriting large portions of
> the code in C?

No, it just requires a lot of rewriting with an eye towards better performance.

Hadley


--
http://had.co.nz/

Reply all
Reply to author
Forward
0 new messages