# [R] Simple Question: adding points to a boxplot

Farley, Robert FarleyR at metro.net
Mon Aug 10 19:37:39 CEST 2009

```I think there's a miss-understanding of my datasets, and why I'm asking this question.

I have one dataframe with ~18 observations ("actual" data) each of ~40 things.  I independently made an estimate using a very complex model resulting in a value for each of those 40 things.

I created a boxplot showing the variation in the observed values for those ~40 things, and also plotted the model estimate.  Since the observed and modeled (estimated) came from two different and independent sources, I was concerned that the ordering could be different, and maybe even a misspelling crept in.

The ordering of the two elements (dataframes of the plot were not "related".  They were simply the order that they occurred in the two dataframes, with names (labels) taken from the first.  That is, I needed to read the two dataframes and manually verify that they were in the same order.  I could have easily gotten them in a different order, in which case my plot would be showing a poor relationship between observed and estimated.

I want to thank all of you who've helped me thus far.  R is a very powerful package, but with that power comes a good deal of complexity.  Since I don't fully understand this very complex language, I can imagine many ways in which what I'm doing is wrong.

Robert Farley
Metro
www.Metro.net

PS, My working code:
# ------------------------------------------------------------------------------------------------
# Boxplot(observed) with modeled
boxplot(ObsRpdData)
points(1:length(EstRpdData),EstRpdData, pch=16, col="red")   # pch=16 = solid circle
# ------------------------------------------------------------------------------------------------

-----Original Message-----
From: Phil Spector [mailto:spector at stat.berkeley.edu]
Sent: Friday, August 07, 2009 19:00
To: Farley, Robert
Subject: Re: [R] Simple Question: adding points to a boxplot

Robert -
Don't you mean

points(1:length(EstRpdData),apply(EstRpdData,2,mean,na.rm=TRUE),pch=16,col="red")

As to your question, I'm not sure I know what you mean.  If you use the output
of apply, the order will be the same as the original data frame.    You may want
to take a look at the merge function.

- Phil

On Fri, 7 Aug 2009, Farley, Robert wrote:

> Sorry to keep bothering you all.  Phil's easy fix got my code working and I have my graphic.
>
> Just for my education: Is there a SIMPLE way to verify/ensure that the ordering of the data is the same in both dataframes?  Is this done within the plotting routines, or is it usually as a data checking process before data analysis?
>
>
> ==============================================
> boxplot(ObsRpdData)
> points(1:length(EstRpdData),EstRpdData, pch=16, col="red)
> ===============================================
>
>
>
> Robert Farley
> Metro
> www.Metro.net
>
>
> -----Original Message-----
> From: Farley, Robert
> Sent: Friday, August 07, 2009 15:56
> To: 'Phil Spector'
> Subject: RE: [R] Simple Question: adding points to a boxplot
>
> Whoo-hoo, I get the points!
>
> Thanks!
>
> I guess I was over-thinking it.  :-)
>
>
>
>
>
> Robert Farley
> Metro
> www.Metro.net
>
> -----Original Message-----
> From: Phil Spector [mailto:spector at stat.berkeley.edu]
> Sent: Friday, August 07, 2009 15:53
> To: Farley, Robert
> Subject: Re: [R] Simple Question: adding points to a boxplot
>
> Robert -
>    What happens when you try
>
> points(1:length(Est1),Est1, pch=23, col="red")
>
>                                        - Phil Spector
>                                         Statistical Computing Facility
>                                         Department of Statistics
>                                         UC Berkeley
>                                         spector at stat.berkeley.edu
>
>
>
>
> On Fri, 7 Aug 2009, Farley, Robert wrote:
>
>> I apologize in advance for the simplicity of this question.  I use R 2-3 times a year, and I seem to forget more in the intervening months than I learn during my days of panicked reading....  I HAVE tried looking at the help resources; I'm just not very good at understanding them.
>>
>> I have a dataframe with 18 observations of 5 different things, and a second dataframe with and estimate for those 5 things.  I'm trying to add the estimated points to the boxplot of observations.  I THINK I'm failing because I need to decompose my estimated dataframe into two vectors.  I can't seem to figure out how to do that properly, or if I'm suffering from a different misunderstanding....
>>
>>
>> ======================================
>> The following code creates the box plot,
>> but the points are not added
>> ======================================
>>> Obs1
>>    Blue Green    Red  Gold Orange
>> 1  77902 32911 117543 18245     NA
>> 2  77294 32204 114927 18377     NA
>> 3  75737 31484 115265 18529     NA
>> 4  73366 31130 112371 14748     NA
>> 5  77061 33601 118113 16910  16360
>> 6  75177 32383 113825 14417  15492
>> 7  76766 35697 124304 16318  16100
>> 8  80378 36374 128091 15325  17636
>> 9  84078 37473 138219 15769  18242
>> 10 81704 37247 136345 15587  18700
>> 11 84554 39134 143830 18078  21828
>> 12 80411 37487 137583 18771  20844
>> 13 76103 34734 131469 20329  20760
>> 14 76246 34591 127921 18874  19531
>> 15 72025 33645 118279 20972  21005
>> 16 72295 35153 121752 18035  20217
>> 17 71287 32961 121958 17768  20659
>> 18 71778 32833 123990 17956  19004
>>> Est1
>>   Blue Green    Red  Gold Orange
>> 1 72289 32444 107121 20900  21962
>>> boxplot(Obs1)
>>> points(Est1, pch=23, col="red")
>>>
>> ======================================
>>
>>
>>
>>
>>
>>
>> Robert Farley
>> Metro
>> 1 Gateway Plaza
>> Mail Stop 99-23-7
>> Los Angeles, CA 90012-2952
>> Voice: (213)922-2532
>> Fax:    (213)922-2868
>> www.Metro.net
>>
>>
>>
>>       [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help