[R] help with recalling data points in a specific region of the plot

David Winsemius dwinsemius at comcast.net
Tue Aug 25 03:58:18 CEST 2009


On Aug 24, 2009, at 6:50 PM, Edward Chen wrote:

> Thank you so much for your reply. I apologize for not making my  
> question clearer.
> The problem I have right now is not just a matrix. I have a plot in  
> which the X and Y are both calculated by other functions before the  
> plot. After reviewing the plot, there are some areas of the plot  
> that do not look correct. I just want to know if there's a way to  
> know what the x and y coordinate of those points are and display  
> them on the graph if possible. the specific region that I am looking  
> for is 0<x<1 and y<0.5. Hope this would clarify some confusions.
> Thank you again!

Two thoughts
a)  which would seem that the blindingly obvious strategy ... no  
dataframe? Then make one:

df1 <- data.frame(X =X, Y=Y)

    .... and proceed as suggested.

... or try .... still using your original limits:

with(df1[df1$X>5&df1$Y>5, ], text(X, Y,
          paste( sprintf(fmt="%0.2f", X),  sprintf(fmt="%0.2f", Y) ) ) )

... or print their row numbers ....

df1$Rw <- 1:nrow(df1)

with(df1[df1$X>5&df1$Y>5, ], text( X, Y, paste("row=", Rw) ) )

b) the dataframeless approach:  create an index for the joint  
conditions on X and Y and then use that index to reference their  
values. To use you new conditions, that would be;

idx <- X > 0 & X < 1 & Y < 0.5
plot(X[idx], Y[idx], col="red"")

... or print the (X,Y) values with sprintf as illustrated above.



>
> On Mon, Aug 24, 2009 at 10:52 AM, David Winsemius <dwinsemius at comcast.net 
> > wrote:
>
> On Aug 24, 2009, at 12:55 PM, Edward Chen wrote:
>
> Hi all,
>
> Is there a quick way to display or recall data points from a  
> specific region
> on the plot? For example I want the points from x>5 and y>5?
> Thank you very much!
>
> Your question is pretty light on specifics but assuming that you  
> have columns  x and y  in a dataframe, df1, then in ordinary  
> graphics you could just execute this after another plotting function  
> has been performed:
>
> with(subset(df1, x>5 & y>5), points(x,y, col="red") )
>
> # I generally make my points smaller with cex=0.2 or cex=0.1
>
> subset(f1, x>5 & y>5)[ , c("x","y")]
> # should "recall" the values, if my wetware R interpreter is working  
> properly.
>
>
> -- 
> Edward Chen

David Winsemius, MD
Heritage Laboratories
West Hartford, CT




More information about the R-help mailing list