[R] how to represent error bar in a plot legend?

Jim Lemon jim at bitwrit.com.au
Thu Sep 2 11:39:26 CEST 2010


On 09/02/2010 04:56 AM, Josef.Kardos at phila.gov wrote:
> I have a simple barplot of 4 mean values, each mean value has an
> associated 95% confidence interval drawn on the plot as an error bar.
> I want to make a legend on the plot that uses the error bar symbol, and
> explains "95% C.I."
> How do I show the error bar symbol in the legend?  I could not find any
> "pch" values that are appropriate
>
Hi Josef,
There is a way to do this, but it is not too easy. First, use the 
my.symbols function in the TeachingDemos package to define the "error 
bar" symbol. Then, you can draw a legend without one or more symbol 
elements and place your "error bar" symbol where the symbol would have 
been. You can see how to do this in the code of the legendg function in 
the plotrix package by getting the necessary coordinates from the legend 
function.

Jim



More information about the R-help mailing list