[R] labeling outliers with subject numberss

Peter Ehlers ehlers at ucalgary.ca
Thu Sep 16 01:42:30 CEST 2010


Kevin,

On 2010-09-15 16:37, Phil Spector wrote:
> Kevin -
>      Here's one way:
>
>> z = boxplot(mydata$score,outline=FALSE,ylim=range(mydata$score))
>> text(1,z$out,SubNo[which(score == z$out)])
>
>   					- Phil Spector
>   					 Statistical Computing Facility
>   					 Department of Statistics
>   					 UC Berkeley
>   					 spector at stat.berkeley.edu
>

You can avoid the explicit setting of ylim (although I would
normally prefer setting it) and use instead:

  z <- boxplot(mydata$score, outpch="")
  text(1, z$out, SubNo[which(score == z$out)])

But note that this only works for a single outlier.
Assuming that your use of SubNo is merely to identify
the score maximum, you might as well use

  with(mydata, boxplot(score, outpch = as.character(which.max(score))))


   -Peter Ehlers

>
> On Wed, 15 Sep 2010, Kevin Burnham wrote:
>
>> How can I get the outlier in this boxplot of "Score" to be represented by
>> the corresponding value in "SubNo"?
>>
>> score=c(6,6,7,14,5,7,6,8)
>> SubNo=1:8
>> mydata=data.frame(SubNo, score)
>> boxplot(mydata$score)
>>
>>
>> Thanks!
>> Kevin



More information about the R-help mailing list