Edward Chen
2009-Aug-24 16:55 UTC
[R] help with recalling data points in a specific region of the plot
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! -- Edward Chen [[alternative HTML version deleted]]
John Kane
2009-Aug-24 17:21 UTC
[R] help with recalling data points in a specific region of the plot
I am assuming that you want to desplay all the data and highlight the subset. Set up a vector to indicate the breakdown of the data and you can do it fairly easily in ggplot2 if you treat the vector as a factor. library(ggplot) mydata <- data.frame(x=1:21, y= -10:10) z <- ifelse(mydata[,1]>5 & mydata[,2] >5, 1, 0) # identify points >5 mydata <- data.frame(mydata, z) ggplot(mydata, aes(x=x, y=y, colour= factor(z))) + geom_point() --- On Mon, 8/24/09, Edward Chen <edchen51 at gmail.com> wrote:> From: Edward Chen <edchen51 at gmail.com> > Subject: [R] help with recalling data points in a specific region of the plot > To: r-help at r-project.org > Received: Monday, August 24, 2009, 12:55 PM > 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! > > -- > Edward Chen > > ??? [[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. >__________________________________________________________________ Looking for the perfect gift? Give the gift of Flickr! http://www.flickr.com/gift/
David Winsemius
2009-Aug-24 17:52 UTC
[R] help with recalling data points in a specific region of the plot
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. David Winsemius, MD Heritage Laboratories West Hartford, CT
David Winsemius
2009-Aug-25 01:58 UTC
[R] help with recalling data points in a specific region of the plot
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 ChenDavid Winsemius, MD Heritage Laboratories West Hartford, CT