[R] Dot plot similar to StatKey

S Ellison S.Ellison at LGCGroup.com
Tue Jul 30 20:08:46 CEST 2013


 

I said:
> stripchart(xr, method="stack", pch=19) 

> will do this if the data are rounded appropriately. You may 
> have some fun with 'appropriately'.
> 

A bit of tinkering gives something that gets close to 'appropriate' (below); you may want to tinker with the tuning factor (or, of course, write something entirely different).

#
# Based on ?points: For 'pch' in '0:25' the default size is about
#          75% of the character height (see 'par("cin")')

round.pch<-function(x, tune=1.0) {
	#produces data rounded to approximate graphics symbol width
                is.window <- !is.null(dev.list()[1])
	if(is.window) {
		psize.ins <- 0.75 * par("cin")[2]/(2 * tune)
		psize.usr <- psize.ins*diff(par("usr")[1:2] / par("pin")[1])
	} else {
		psize.usr <- diff(range(pretty(x))) * 0.15 / (14 * tune)
		               #0.15 is the default par("cin")[2] * 0.75
	}
	return( psize.usr * (floor(x/psize.usr) + 0.5) ) 
}

set.seed(73)
x<-rnorm(500)
stripchart(round.pch(x), method="stack", pch=19, ylim=c(0.9,2))


round.pch above uses a vaguely reasonable default rounding with no graphics device present and will use the present device size and units if you have already called plot.new and set user coordinates. Odd things wll happen with a device open and no user coordinates set. Calling this repeatedly with no xlim set in stripchart will cause results to vary visibly as the user coordinates change slightly for each call.

*******************************************************************
This email and any attachments are confidential. Any use...{{dropped:8}}



More information about the R-help mailing list