[R] Graphical output: dials and meters for a dashboard?

Greg Snow Greg.Snow at imail.org
Tue Jan 15 19:52:07 CET 2008


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.
> 




More information about the R-help mailing list