[R] Drawing lines in margins

2009-07-29 Thread Alan Cohen
Hi all,

Quick question: What function can I use to draw a line in the margin of a plot? 
 segments() and lines() both stop at the margin.

In case the answer depends on exactly what I'm trying to do, see below.  I'm 
using R v. 2.8.1 on Windows XP.

Cheers,
Alan

I'm trying to make a horizontal barplot with a column of numbers on the right 
side.  I'd like to put a line between the column header and the numbers.  The 
following reconstructs the idea - just copy and paste it in:
aa - 1:10
plot.mtx2-cbind(aa,aa+1)
colnames(plot.mtx2)-c(Male,Female)
lci2- cbind(aa-1,aa)
uci2- cbind(aa+1,aa+2)
par(mar=c(5,6,4,5))
cols - c(grey79,grey41)
bplot2-barplot(t(plot.mtx2),beside=TRUE,xlab=Malaria death rates per 100,000,
names.arg=paste(state,aa,sep=),legend.text=F,las=1,xlim=c(0,13), horiz=T, 
col=cols,
main=Malaria death rates by state and sex)
legend(8,6,legend=c(Female,Male),fill=cols[order(2:1)])
segments(y0=bplot2, y1=bplot2, x0=t(lci2), x1=t(uci2))
mtext(10*(aa+1),side=4,line=4,at=seq(3,3*length(aa),by=3)-0.35,padj=0.5,adj=1,las=1,cex=0.85)
mtext(10*aa,side=4,line=4,at=seq(2,3*length(aa)-1,by=3)-0.65,padj=0.5,adj=1,las=1,cex=0.85)
mtext(Estimated,side=4,line=3,at=3*length(aa)+2.75,padj=0.5,adj=0.5,las=1,cex=0.85)
mtext(Deaths,side=4,line=3,at=3*length(aa)+1.25,padj=0.5,adj=0.5,las=1,cex=0.85)

__
R-help@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.


Re: [R] Drawing lines in margins

2009-07-29 Thread Nutter, Benjamin
Look at the xpd option in ?par.  If you set par(xpd=TRUE) you should be
able to add a segment for what you want.  But please let me know if
someone gives you a better way to do this.

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On Behalf Of Alan Cohen
Sent: Wednesday, July 29, 2009 10:22 AM
To: r-help@r-project.org
Subject: [R] Drawing lines in margins

Hi all,

Quick question: What function can I use to draw a line in the margin of
a plot?  segments() and lines() both stop at the margin.

In case the answer depends on exactly what I'm trying to do, see below.
I'm using R v. 2.8.1 on Windows XP.

Cheers,
Alan

I'm trying to make a horizontal barplot with a column of numbers on the
right side.  I'd like to put a line between the column header and the
numbers.  The following reconstructs the idea - just copy and paste it
in:
aa - 1:10
plot.mtx2-cbind(aa,aa+1)
colnames(plot.mtx2)-c(Male,Female)
lci2- cbind(aa-1,aa)
uci2- cbind(aa+1,aa+2)
par(mar=c(5,6,4,5))
cols - c(grey79,grey41)
bplot2-barplot(t(plot.mtx2),beside=TRUE,xlab=Malaria death rates per
100,000,
names.arg=paste(state,aa,sep=),legend.text=F,las=1,xlim=c(0,13),
horiz=T, col=cols,
main=Malaria death rates by state and sex)
legend(8,6,legend=c(Female,Male),fill=cols[order(2:1)])
segments(y0=bplot2, y1=bplot2, x0=t(lci2), x1=t(uci2))
mtext(10*(aa+1),side=4,line=4,at=seq(3,3*length(aa),by=3)-0.35,padj=0.5,
adj=1,las=1,cex=0.85)
mtext(10*aa,side=4,line=4,at=seq(2,3*length(aa)-1,by=3)-0.65,padj=0.5,ad
j=1,las=1,cex=0.85)
mtext(Estimated,side=4,line=3,at=3*length(aa)+2.75,padj=0.5,adj=0.5,la
s=1,cex=0.85)
mtext(Deaths,side=4,line=3,at=3*length(aa)+1.25,padj=0.5,adj=0.5,las=1
,cex=0.85)

__
R-help@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.


===

P Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S. News  World Report (2008).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use\...{{dropped:13}}

__
R-help@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.


Re: [R] Drawing lines in margins

2009-07-29 Thread Greg Snow
In addition to Benjamin's response (which is the best way that I know of), you 
may also want to look at the grconvertX and grconvertY functions for ways to 
find the coordinates in the margins to plot at.

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
 project.org] On Behalf Of Nutter, Benjamin
 Sent: Wednesday, July 29, 2009 8:56 AM
 To: Alan Cohen
 Cc: r-help@r-project.org
 Subject: Re: [R] Drawing lines in margins
 
 Look at the xpd option in ?par.  If you set par(xpd=TRUE) you should be
 able to add a segment for what you want.  But please let me know if
 someone gives you a better way to do this.
 
 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
 project.org]
 On Behalf Of Alan Cohen
 Sent: Wednesday, July 29, 2009 10:22 AM
 To: r-help@r-project.org
 Subject: [R] Drawing lines in margins
 
 Hi all,
 
 Quick question: What function can I use to draw a line in the margin of
 a plot?  segments() and lines() both stop at the margin.
 
 In case the answer depends on exactly what I'm trying to do, see below.
 I'm using R v. 2.8.1 on Windows XP.
 
 Cheers,
 Alan
 
 I'm trying to make a horizontal barplot with a column of numbers on the
 right side.  I'd like to put a line between the column header and the
 numbers.  The following reconstructs the idea - just copy and paste it
 in:
 aa - 1:10
 plot.mtx2-cbind(aa,aa+1)
 colnames(plot.mtx2)-c(Male,Female)
 lci2- cbind(aa-1,aa)
 uci2- cbind(aa+1,aa+2)
 par(mar=c(5,6,4,5))
 cols - c(grey79,grey41)
 bplot2-barplot(t(plot.mtx2),beside=TRUE,xlab=Malaria death rates per
 100,000,
 names.arg=paste(state,aa,sep=),legend.text=F,las=1,xlim=c(0,13),
 horiz=T, col=cols,
 main=Malaria death rates by state and sex)
 legend(8,6,legend=c(Female,Male),fill=cols[order(2:1)])
 segments(y0=bplot2, y1=bplot2, x0=t(lci2), x1=t(uci2))
 mtext(10*(aa+1),side=4,line=4,at=seq(3,3*length(aa),by=3)-
 0.35,padj=0.5,
 adj=1,las=1,cex=0.85)
 mtext(10*aa,side=4,line=4,at=seq(2,3*length(aa)-1,by=3)-
 0.65,padj=0.5,ad
 j=1,las=1,cex=0.85)
 mtext(Estimated,side=4,line=3,at=3*length(aa)+2.75,padj=0.5,adj=0.5,l
 a
 s=1,cex=0.85)
 mtext(Deaths,side=4,line=3,at=3*length(aa)+1.25,padj=0.5,adj=0.5,las=
 1
 ,cex=0.85)
 
 __
 R-help@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.
 
 
 ===
 
 P Please consider the environment before printing this e-mail
 
 Cleveland Clinic is ranked one of the top hospitals
 in America by U.S. News  World Report (2008).
 Visit us online at http://www.clevelandclinic.org for
 a complete listing of our services, staff and
 locations.
 
 
 Confidentiality Note:  This message is intended for
 use\...{{dropped:13}}
 
 __
 R-help@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.

__
R-help@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.