[R] Specifying plot area in dotchart2

Ryan Derickson rlderickson at gmail.com
Sat Dec 20 16:29:00 CET 2014


Hello,

I'm producing multiple dotcharts and I want each plotting area (the area
containing the dots only- not the labels) to be the same width. Currently,
the width of the area depends on the length of the labels. I've tried
different margin arguments but they change the parameter of the whole plot
(dots + labels) rather than just the dot area.

A reproducible example is below; I want the dot area to be the same
physical width across charts regardless of the label width. Any suggestions
would be greatly appreciated!

Ryan Derickson


library(Hmisc)
pdf("dotchart2 demo.pdf")

# This plot width is wider

par(omi=c(0, 2, 0, 0), mar=c(2,4,1,1))

num<-rnorm(40, 0, 1)
lab<-paste(rep(letters[1:20],2),rep(letters[1:20],2),rep(letters[1:20],2),rep(letters[1:20],2)

 ,rep(letters[1:20],2),rep(letters[1:20],2),rep(letters[1:20],2),rep(letters[1:20],2),
sep="")

dat<-data.frame(num, lab)
dat<-dat[order(num),]

dotchart2(dat$num, label=dat$lab, xlim=c(-3,3))


# This plot width is narrower

par(omi=c(0, 2, 0, 0), mar=c(2,4,1,1))

num<-rnorm(40, 0, 1)
lab<-paste(rep(letters[1:20],2),rep(letters[1:20],2),rep(letters[1:20],2),rep(letters[1:20],2),
sep="")

dat<-data.frame(num, lab)
dat<-dat[order(num),]

dotchart2(dat$num, label=dat$lab, xlim=c(-3,3))

dev.off()

	[[alternative HTML version deleted]]



More information about the R-help mailing list