[R] Barplot

Marc Schwartz (via MN) mschwartz at mn.rr.com
Mon Oct 2 19:23:34 CEST 2006


On Mon, 2006-10-02 at 11:14 -0400, Mohsen Jafarikia wrote:
> Hello,
> 
> I have used the following data to draw my barplot:
> 
> BL         LR    Q
> 
> 36.35    1.00   1.92
> 36.91    4.00   0.00
> 25.70    6.00   0.00
> 34.38    3.00   1.92
> 05.32    0.50   0.00
> 
>  BL<-c(36.35, 36.91, 25.70, 34.38, 05.32)
> LR<-c(1.00, 4.00, 6.00, 3.00, 0.50)
> Q<-<(1.92, 0.00, 0.00, 1.92, 0.00)
> 
> barplot(dt$LR, main='LR Value',  col='orange', border='black', space=0.05,
> width=(dt$BL), xlab='Length', ylab='LR')
> 
>  axis(1)
> 
> I would like to do the following things that I don't know how to do it:
> 
>       1)      Writing the value of each 'BL' on my X axis.
> 2)      Writing the value of 'Q' on the bottom of  X axis.
> 3)      Draw a line on the bars which connects the 'LR' values.
> 
>  I appreciate your comments.
> 
>  Thanks,
> Mohsen


I'm not sure if I am getting this completely correct, but is this what
you want?


BL <- c(36.35, 36.91, 25.70, 34.38, 5.32)
LR <- c(1.00, 4.00, 6.00, 3.00, 0.50)
Q <- c(1.92, 0.00, 0.00, 1.92, 0.00)


# Get the bar midpoints in 'mp'
mp <- barplot(LR, main='LR Value',  col='orange', border='black',
              space=0.05, width=(BL), xlab='Length', ylab='LR')

# Write the LR and Q values below the bar midpoints
mtext(1, at = mp, text = sprintf("%.1f", LR), line = 1)
mtext(1, at = mp, text = sprintf("%.1f", Q), line = 0)

# Now connect the LR values across the bars
lines(mp, LR)


See ?barplot, ?mtext, ?sprintf and ?lines

HTH,

Marc Schwartz



More information about the R-help mailing list