Parker Jones
2008-Jan-15 16:39 UTC
[R] Graphical output: dials and meters for a dashboard?
Hello, I'm new to R and am evaluating it to see whether it would be an appropriate tool to create a "dashboard" (a graphical statistical summary page). Could someone tell me if it is possible to display data as dials or meters. e.g. the four dials here: http://www.pentaho.com/images/snap_dashboard_1.png Browsing the site hasn't revealed anything yet. Thanks for any suggestions, PJ
hadley wickham
2008-Jan-15 18:41 UTC
[R] Graphical output: dials and meters for a dashboard?
> I'm new to R and am evaluating it to see whether it would be an appropriate tool to create a "dashboard" (a graphical statistical summary page). Could someone tell me if it is possible to display data as dials or meters. e.g. the four dials here: http://www.pentaho.com/images/snap_dashboard_1.pngThe question would why would you want to? You are trying to understand your data, not driving a race car or aeroplane. You might want to check out the books and writing of Stephen Few (http://www.perceptualedge.com) who makes this case powerfully and eloquently, and also suggests alternatives that are far more useful. Hadley -- http://had.co.nz/
Here is a quick and dirty function to do so (things can easily be changed to reflect preferences): dial <- function(x, min=0, max=1){ old.par <- par(pty='s', lend=1) on.exit(par(old.par)) plot(0,0, pch=16, cex=5, ann=FALSE, xaxt='n', yaxt='n', xlab='', ylab='', xlim=c(-1,1), ylim=c(-1,1) ) tmp.theta <- seq( -1/3*pi, 4/3*pi, length=11 ) segments( 0.9 * cos(tmp.theta), 0.9 * sin(tmp.theta), cos(tmp.theta), sin(tmp.theta) ) tmp.theta <- seq(4/3*pi, 5/6*pi, length=100) lines( cos(tmp.theta), sin(tmp.theta), col='red', lwd=5 ) tmp.theta <- seq(5/6*pi, 1/6*pi, length=100) lines( cos(tmp.theta), sin(tmp.theta), col='yellow', lwd=5 ) tmp.theta <- seq(1/6*pi, -1/3*pi, length=100) lines( cos(tmp.theta), sin(tmp.theta), col='green', lwd=5 ) tmp.theta <- seq(0,2*pi, length=360) lines( 1.025*cos(tmp.theta), 1.025*sin(tmp.theta) ) tmp.theta <- (max-x)/(max-min) * 5/3*pi - pi/3 polygon( c(.05, 1, 0.05) * cos( tmp.theta + c(-pi/2,0,pi/2) ), c(0.05, 1, 0.05) * sin( tmp.theta + c(-pi/2,0,pi/2) ), col='black') text( 0,-0.9, x ) } Now you can do type:> dial(.72) > title(main='Your Title Here')Or> dial( 57, 30,150 )Multiple dials can be created using par(mfrow= ... Or the my.symbols function from the TeachingDemos package. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org (801) 408-8111> -----Original Message----- > From: r-help-bounces at r-project.org > [mailto:r-help-bounces at r-project.org] On Behalf Of Parker Jones > Sent: Tuesday, January 15, 2008 9:39 AM > To: r-help at r-project.org > Subject: [R] Graphical output: dials and meters for a dashboard? > > > Hello, > > I'm new to R and am evaluating it to see whether it would be > an appropriate tool to create a "dashboard" (a graphical > statistical summary page). Could someone tell me if it is > possible to display data as dials or meters. e.g. the four > dials here: http://www.pentaho.com/images/snap_dashboard_1.png > > Browsing the site hasn't revealed anything yet. > > Thanks for any suggestions, > PJ > > ______________________________________________ > 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. >
Parker Jones
2008-Jan-16 13:51 UTC
[R] Graphical output: dials and meters for a dashboard?
> You can do a basic dial with something like this: >Thanks Jim. After installing plotrix I still had a bit of trouble getting this to work and I don't (yet) know enough R to fix it:> speedoplot(0.5,5,5,2,"Speedoplot")Error in polygon(xv, yv, border = border, col = col, lty = lty, lwd = lwd) : plot.new has not been called yet But the error went away if I plotted something else first. Also the colour bands are skewed - but that may just be a side-effect of my other plot.> and if you want something fancier, you can call a 3D renderer like POVRay: > > http://www.povray.org > > to render very realistic objects.Sounds interesting, but probably a bit overkill at this stage. Thanks again for coding up the dial! PJ