Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Label outliers in an scatter plot

I've plot this graphic to identify graphically high-leverage points in my linear model. enter image description here

Given the variable "NOMBRES" of the data set which my model uses, I've tried to plot all the points of my graphic but it gets illegible. Here's the code I ran:

> plot(hatvalues(tmodel),residuals(tmodel))
> text(hatvalues(tmodel),residuals(tmodel),labels=DSET$NOMBRES)

So I would like to plot just the points with leverage(hat value) above 0.05 using the label "DSET$NOMBRES".

like image 344
CreamStat Avatar asked Feb 11 '14 17:02

CreamStat


People also ask

How do you label outliers in a scatter plot?

The “identify” tool in R allows you to quickly find outliers. You click on a point in the scatter plot to label it. You can place the label right by clicking slightly right of center, etc. The label is the row number in your dataset unless you specify it differenty as below.

How do you label each point on a scatter plot in R?

To add the labels, we have text() , the first argument gives the X value of each point, the second argument the Y value (so R knows where to place the text) and the third argument is the corresponding label. The argument pos=1 is there to tell R to draw the label underneath the point; with pos=2 (etc.)


1 Answers

Identify high-leverage points according to your definition:

hlev <- which(hatvalues(tmodel)>0.05)

Add numeric labels to the graph:

text(hatvalues(tmodel)[hlev], residuals(tmodel)[hlev], 
   labels=DSET$NOMBRES[hlev])
like image 150
Ben Bolker Avatar answered Oct 13 '22 18:10

Ben Bolker