Maciej
Maciej

Reputation: 3303

Dashboards - (dial) meters in R

I'm wondering if it is possible to do this kind of dashboards in R (I mean this kind of plots)?

Here is examples which I want to do in R (first is from SAS)

edit: i work on Windows 7 (64bit).

enter image description here

enter image description here

Upvotes: 2

Views: 1519

Answers (3)

jverzani
jverzani

Reputation: 5700

Here is something to start with using base graphics. Making it prettier is left to the reader. You can see an example in action here: http://www.math.csi.cuny.edu/gw/ex-dashboard.R .

dashboard <- function(dial=list(
                        list(color="red",
                             range=c(10, 40)),
                        list(color="yellow",
                             range=c(40, 60)),
                        list(color="green",
                             range=c(70, 100))
                        ),
                      value=from) {


  from <- min(unlist(lapply(dial, "[[", i="range")))
  to <-  max(unlist(lapply(dial, "[[", i="range")))

  theta <- seq(-pi/3, pi + pi/3, length=100)
  r <- 1

  scale <- function(x) {
    m <- (pi + pi/3 - (-pi/3))/(from - to)
    (pi + pi/3) + m*(x - from)
  }

  plot.new()
  plot.window(xlim=c(-1, 1), ylim=c(sin(-pi/3), 1))

  lines(cos(theta), sin(theta))
  sapply(dial, function(l) {
    d <- scale(l$range)
    x <- seq(d[1], d[2], length=100)
    lines(cos(x), sin(x), col=l$color, lwd=3)
  })

  ticks <- pretty(c(from, to), n=5)
  ticks_th <- scale(ticks)
  r <- 1 - .15
  text(r*cos(ticks_th), r*sin(ticks_th), labels=ticks)

  sapply(ticks_th, function(th) {
    lines(cos(th)*c(1,.95), sin(th)*c(1, .95))
  })

  r <- 1 - .25
  th <- scale(value)
  arrows(0, 0, cos(th), sin(th))


}

dashboard( value=60)

Upvotes: 7

Ari B. Friedman
Ari B. Friedman

Reputation: 72739

You can do something similar with polar plots:

require(plotrix)
polar.plot( c(0,20),c(0,60),main="Dashboard",lwd=3,line.col=4)

You can dig deeper into the code if you want to customize the look. Using radial.plot may give you more customization.

polar plot

Upvotes: 5

Dirk is no longer here
Dirk is no longer here

Reputation: 368351

This has little to do with R, but only with how to get hold of GUI widgets representing dashboard items.

I think Gtk2 may do that, so the RGtk2 package (and its wrappers) could be of help. I know for a fact that the Qwt toolkit has, but that one is more difficult to access (as you need a C++ bridge).

Upvotes: 2

Related Questions