[R] Dot plot - equivalent of MINITAB
Greg Snow
Greg.Snow at imail.org
Fri Sep 26 19:46:06 CEST 2008
Does the 'dots' function in the TeachingDemos package do what you want? (It fits one interpretation of your description, but my minitab is a bit rusty, so not sure).
(The "you" above referring to kerfuffle, not Rolf, for some reason I received the reply, but not the original).
--
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 Rolf Turner
> Sent: Thursday, September 25, 2008 2:57 PM
> To: kerfuffle
> Cc: r-help at r-project.org
> Subject: Re: [R] Dot plot - equivalent of MINITAB
>
>
> On 26/09/2008, at 7:51 AM, kerfuffle wrote:
>
> >
> > hi folks,
> >
> > Bit of a newbie, but I've spent a fair bit of time looking for an
> > answer on
> > this, with no joy. Can anyone help me?
> >
> > Dataset: A single column of values in a csv file (eg. 52, 53, 54,
> > 85, etc)
> >
> > Goal: In Minitab, you have what they call a dot plot. It's a
> > histogram,
> > where a single dot represents a set of identical values (eg. 57,
> > 57, 57
> > would be one dot). Multiple dots are stacked on top of each other
> > (as if
> > gravity was affecting them). The advantage is that outliers are
> > very visible
> > (since a single 155 still gets a single dot). The net effect is a
> > rug plot,
> > but in the main portion of the plot, not just on the axis.
> >
> > Tried: I've played with dotchart and dotchart2 with no joy (eg.
> > dotchart(nc$bac) (where nc is the dataset and bac is the column
> > header).
> > They do provide multiple dots (so that ten values of 57 are given 3
> > dots)
> > but these overlap and aren't arranged in a logical way. Sometimes
> > a single
> > dot has a large y-value, sometimes it isn't. As a result of this
> > non-gravitational effect, it doesn't look like a histogram at all.
> > It's
> > also strange that the background of the plot is stripy. This
> > implies I'm
> > doing something very wrong, but don't know what. I had a look at
> > the plot
> > galleries, and didn't see anything else that looked like what I
> wanted
> > (except the rug plots).
>
> Here's something that will do at least roughly what you want. The
> fundamentals of this function were written for me by Barry Rowlingson.
> (Thanks Baz!)
>
> dotplot.mtb <- function (x, xlim = NULL, main = NULL, xlab = NULL,
> pch = 19,
> hist = FALSE, yaxis = FALSE)
> {
> if (is.null(xlim))
> xlim <- range(pretty(range(x)))
> if (is.null(main))
> main <- ""
> if (is.null(xlab))
> xlab <- ""
> x <- sort(x)
> w <- table(x)
> mw <- max(w)
> w <- unlist(lapply(w, function(n) {
> 1:n
> }))
> Nmax <- floor(par()$pin[2]/strheight("o", units = "inches"))
> if (mw <= Nmax & !hist) {
> plot(range(x, na.rm = TRUE), c(0, 1), type = "n", xlab = "",
> ylab = "", xlim = xlim, main = main, axes = FALSE)
> par(usr = c(par()$usr[1:2], -Nmax/2, Nmax/2))
> y <- strheight("o") * w
> points(x, y, pch = pch)
> axis(side = 1, pos = 0)
> if (yaxis) {
> a <- 0
> b <- round(Nmax/10)
> at <- seq(a, by = b, length = 10)
> axis(side = 2, at = at)
> }
> }
> else {
> if (hist)
> plot(x, w, type = "h", xlab = "", ylab = "", xlim = xlim,
> ylim = c(-mw - 1, mw + 1), main = main, axes = FALSE)
> else plot(x, w, pch = pch, xlab = "", ylab = "", xlim = xlim,
> ylim = c(-mw - 1, mw + 1), main = main, axes = FALSE)
> axis(side = 1, pos = -0.02 * mw)
> if (yaxis) {
> a <- 0
> b <- max(1, round(mw/10))
> at <- seq(a, by = b, length = 10)
> axis(side = 2, at = at)
> }
> }
> }
>
>
> cheers,
>
> Rolf Turner
>
> ######################################################################
> Attention:\ This e-mail message is privileged and
> confid...{{dropped:9}}
>
> ______________________________________________
> 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