Josef.Kardos at phila.gov
2010-Sep-01 18:56 UTC
[R] how to represent error bar in a plot legend?
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 Thanks [[alternative HTML version deleted]]
Can you give us a working example of what you are doing? I don't understand why you would need a pch symbol for an error bar. Perhaps if you are using an unboxed legend you could just use arrow() and text() to add the error bar to the legend? --- On Wed, 9/1/10, Josef.Kardos at phila.gov <Josef.Kardos at phila.gov> wrote:> From: Josef.Kardos at phila.gov <Josef.Kardos at phila.gov> > Subject: [R] how to represent error bar in a plot legend? > To: r-help at r-project.org > Received: Wednesday, September 1, 2010, 2:56 PM > 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 > > Thanks > ??? [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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. >
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
Josef.Kardos at phila.gov
2010-Sep-02 13:13 UTC
[R] how to represent error bar in a plot legend?
I think I found a simple solution, although it requires some tinkering to find the x,y coordinates of the plot region to place the text... barplot ( ) text(x= 2.9, y = 0.43, srt=90, labels = "H", cex = 1.5, col="blue") #srt rotates the "H" character, so that it resembles an error bar text(x=3.5, y=0.432, labels = "95% C.I.", cex=1.1) rect (2.62,.41,3.9,.45) #draws box around text [[alternative HTML version deleted]]
Seemingly Similar Threads
- basic question about t-test with adjusted p value
- how to make a barplot similar to Excel’s “clustered column chart”.
- Problem loading rJava
- any feedback on XL Solutions Courses for R?
- plotting time series with data gap using type line- but do not want to connect gap with line