[R] Draw vertical line segments between pairs of points

Jim Lemon jim at bitwrit.com.au
Fri Feb 3 09:59:39 CET 2012


On 02/03/2012 12:07 AM, Mohamed Lajnef wrote:
> Dear all,
>
> How to add /*vertical*/ lines above bar graph to display p-values  (
> between pairs of points )?
>
Hi Mohamed,
The "segments" function will do this, but I'm not quite sure of what you 
want to display. Let's say you have a bar plot like this:

heights<-c(2,6,3,5,4,7)
xpos<-barplot(heights,ylim=c(0,10),main="The Bar Plot",
  names.arg=c("First","Second","Third","Fourth","Fifth","Sixth"))

The centers of the bars are now in "xpos", and the heights of the bars 
are in "heights". To draw vertical lines of one unit length above each bar:

segments(xpos,heights,xpos,heights+1)

If you want to display p-values above each bar:

text(xpos,heights+1.1,
  paste("p=",c(0.09,0.003,0.07,0.007,0.05,0.001),sep=""))

Is that the idea?

Jim



More information about the R-help mailing list