identify with mfcol=c(1,2)

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

identify with mfcol=c(1,2)

John Sorkin
I would like to have a figure with two graphs. This is easily accomplished using mfcol:

oldpar <- par(mfcol=c(1,2))
plot(x,y)
plot(z,x)
par(oldpar)

I run into trouble if I try to use identify with the two plots. If, after identifying points on my first graph I hit the ESC key, or hitting stop menu bar of my R session, the system stops the identification process, but fails to give me my second graph. Is there a way to allow for the identification of points when one is plotting to graphs in a single graph window? My code follows.

plotter <- function(first,second) {
  # Allow for two plots in on graph window.
  oldpar<-par(mfcol=c(1,2))
 
  #Bland-Altman plot.
  plot((second+first)/2,second-first)
  abline(0,0)
  # Allow for indentification of extreme values.
  BAzap<-identify((second+first)/2,second-first,labels = seq_along(data$Line))
  print(BAzap)

  # Plot second as a function of first value.
  plot(first,second,main="Limin vs. Limin",xlab="First (cm^2)",ylab="Second (cm^3)")
  # Add identity line.
  abline(0,1,lty=2,col="red")
  # Allow for identification of extreme values.
  zap<-identify(first,second,labels = seq_along(data$Line))
  print(zap)
  # Add regression line.
  fit1<-lm(first~second)
  print(summary(fit1))
  abline(fit1)
  print(summary(fit1)$sigma)

  # reset par to default values.  
  par(oldpar)

}
plotter(first,second)


Thanks,
John






John David Sorkin M.D., Ph.D.
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing)

Confidentiality Statement:
This email message, including any attachments, is for th...{{dropped:6}}

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: identify with mfcol=c(1,2)

glsnow
I tried your code, first I removed the reference to the global
variable data$Line, then it works if I finish identifying by either
right clicking (I am in windows) and choosing stop, or using the stop
menu.  It does as you say if I press escape or use the stop sign
button (both stop the whole evaluation rather than just the
identifying).

On Tue, Apr 3, 2012 at 8:52 AM, John Sorkin <[hidden email]> wrote:

> I would like to have a figure with two graphs. This is easily accomplished using mfcol:
>
> oldpar <- par(mfcol=c(1,2))
> plot(x,y)
> plot(z,x)
> par(oldpar)
>
> I run into trouble if I try to use identify with the two plots. If, after identifying points on my first graph I hit the ESC key, or hitting stop menu bar of my R session, the system stops the identification process, but fails to give me my second graph. Is there a way to allow for the identification of points when one is plotting to graphs in a single graph window? My code follows.
>
> plotter <- function(first,second) {
>  # Allow for two plots in on graph window.
>  oldpar<-par(mfcol=c(1,2))
>
>  #Bland-Altman plot.
>  plot((second+first)/2,second-first)
>  abline(0,0)
>  # Allow for indentification of extreme values.
>  BAzap<-identify((second+first)/2,second-first,labels = seq_along(data$Line))
>  print(BAzap)
>
>  # Plot second as a function of first value.
>  plot(first,second,main="Limin vs. Limin",xlab="First (cm^2)",ylab="Second (cm^3)")
>  # Add identity line.
>  abline(0,1,lty=2,col="red")
>  # Allow for identification of extreme values.
>  zap<-identify(first,second,labels = seq_along(data$Line))
>  print(zap)
>  # Add regression line.
>  fit1<-lm(first~second)
>  print(summary(fit1))
>  abline(fit1)
>  print(summary(fit1)$sigma)
>
>  # reset par to default values.
>  par(oldpar)
>
> }
> plotter(first,second)
>
>
> Thanks,
> John
>
>
>
>
>
>
> John David Sorkin M.D., Ph.D.
> Chief, Biostatistics and Informatics
> University of Maryland School of Medicine Division of Gerontology
> Baltimore VA Medical Center
> 10 North Greene Street
> GRECC (BT/18/GR)
> Baltimore, MD 21201-1524
> (Phone) 410-605-7119
> (Fax) 410-605-7913 (Please call phone number above prior to faxing)
>
> Confidentiality Statement:
> This email message, including any attachments, is for ...{{dropped:15}}

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: identify with mfcol=c(1,2)

John Sorkin
Thanks!
John

John David Sorkin M.D., Ph.D.
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing)

>>> Greg Snow <[hidden email]> 4/5/2012 4:37 PM >>>
I tried your code, first I removed the reference to the global
variable data$Line, then it works if I finish identifying by either
right clicking (I am in windows) and choosing stop, or using the stop
menu.  It does as you say if I press escape or use the stop sign
button (both stop the whole evaluation rather than just the
identifying).

On Tue, Apr 3, 2012 at 8:52 AM, John Sorkin <[hidden email]> wrote:

> I would like to have a figure with two graphs. This is easily accomplished using mfcol:
>
> oldpar <- par(mfcol=c(1,2))
> plot(x,y)
> plot(z,x)
> par(oldpar)
>
> I run into trouble if I try to use identify with the two plots. If, after identifying points on my first graph I hit the ESC key, or hitting stop menu bar of my R session, the system stops the identification process, but fails to give me my second graph. Is there a way to allow for the identification of points when one is plotting to graphs in a single graph window? My code follows.
>
> plotter <- function(first,second) {
>  # Allow for two plots in on graph window.
>  oldpar<-par(mfcol=c(1,2))
>
>  #Bland-Altman plot.
>  plot((second+first)/2,second-first)
>  abline(0,0)
>  # Allow for indentification of extreme values.
>  BAzap<-identify((second+first)/2,second-first,labels = seq_along(data$Line))
>  print(BAzap)
>
>  # Plot second as a function of first value.
>  plot(first,second,main="Limin vs. Limin",xlab="First (cm^2)",ylab="Second (cm^3)")
>  # Add identity line.
>  abline(0,1,lty=2,col="red")
>  # Allow for identification of extreme values.
>  zap<-identify(first,second,labels = seq_along(data$Line))
>  print(zap)
>  # Add regression line.
>  fit1<-lm(first~second)
>  print(summary(fit1))
>  abline(fit1)
>  print(summary(fit1)$sigma)
>
>  # reset par to default values.
>  par(oldpar)
>
> }
> plotter(first,second)
>
>
> Thanks,
> John
>
>
>
>
>
>
> John David Sorkin M.D., Ph.D.
> Chief, Biostatistics and Informatics
> University of Maryland School of Medicine Division of Gerontology
> Baltimore VA Medical Center
> 10 North Greene Street
> GRECC (BT/18/GR)
> Baltimore, MD 21201-1524
> (Phone) 410-605-7119
> (Fax) 410-605-7913 (Please call phone number above prior to faxing)
>
> Confidentiality Statement:
> This email message, including any attachments, is for ...{{dropped:23}}

______________________________________________
[hidden email] 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.