Monday, July 25, 2011

Creating svg graphics for web publishing

Thanks to the nice post from Revolution Analytics I was finally able to get an svg device working on my Windows OS version of R. It took some additional tips from a fellow user of blogger to figure out out how to embed the result on (due to the inability to upload svg files I had to post the file on Wikimedia Commons and then create a link).

Luckily, I didn't need to rebuild my R version with cairo support - i just installed the R package Cairo and then used its function CairoSVG()

the code for the figure...

angle=rep(seq(0,2*pi, by=2*pi/(n.per.orbit-1)),orbits)
wander<-runif(orbits*n.per.orbit, -1,1)
fit <- smooth.spline(pos)
spl.pred <- predict(fit)$y
COL <- rainbow(length(y))
CairoSVG(file = "circle_art.svg", width = 6, height = 6, bg = "black")
par(mar=c(0,0,0,0), bg="black")
plot(x, y, t="n")
segments(x[1:(length(x)-1)], y[1:(length(y)-1)], 
x1=x[2:length(x)], y1=y[2:length(y)], col=COL, lwd=3, lend=0)
Created by Pretty R at

No comments:

Post a Comment