Skip to content

Options for zooming plots other than zm()

6 messages · Robert Dodier, Deepayan Sarkar, Jeff Newmiller +2 more

#
Hi,

I am making some plots with plot() which have a fair number of points
(thousands) and I would like to be able to interactively select a
region of the plot and zoom in on it. I tried the zoom package which
has the function zm() but I found that it was unworkably slow to
refresh the display. I guess I can set the x and y range via xlim and
ylim but I was hoping to do it interactively. Does someone have a
suggestion for that?

I looked at ggplot2 but I wasn't able to find something about
interactive zooming, only noninteractive via plot limits. Perhaps I
have overlooked something there?

I have searched the mailing list archive and web pages in general but
I haven't found anything other than zm(). Thank you in advance for
your help, I appreciate it very much.

best,

Robert Dodier
#
On Sat 25 Apr, 2020, 12:10 PM Robert Dodier, <robert.dodier at gmail.com>
wrote:
How about plotly? It supports ggplot2 plots through ggplotly().

-Deepayan

  
  
#
Plotly and dygraphs support this.
On April 24, 2020 11:11:44 AM PDT, Robert Dodier <robert.dodier at gmail.com> wrote:

  
    
#
This doesn't answer your question, but I was wondering why having
thousands of data points is problematic?

Sometimes overplotting of points can make plots difficult to interpret.
(This is probably the most common problem plotting large datasets).

Taking this problem (overplotting) in generality, zooming doesn't
necessarily fix the problem, and even if it does there's a risk of
creating other problems.
Simple solutions include using semitransparent points, plotting a
(smaller) sample, or (in a limited range of situations) using
"jitter".
More sophisticated solutions include plotting binned data or plotting
bivariate kernel density estimates.
It's also possible combine approaches, say plot points on top of a
heatmap representing bivariate kernel density estimates.

If the goal is to inspect specific points, say with individual labels,
or plot high density deterministic data, then may be zooming could be
of some value.
#
Hi Robert,
Maybe you can use something simple like this:

zoomInScatterPlot<-function(x=NULL,y,...) {
 if(is.null(x)) x<-1:length(y)
 plot(x,y,...)
 xylim<-par("usr")
 boxed.labels(xylim[1]-diff(xylim[1:2])/20,
  xylim[3]-diff(xylim[3:4])/10,"Done")
 xy1<-locator(1)
 done<-FALSE
 while(!done) {
  if(xy1$x < xylim[1]) done<-TRUE
  else {
   xy2<-locator(1)
   xlim<-c(xy1$x,xy2$x)
   ylim<-c(xy1$y,xy2$y)
   plot(x,y,xlim=xlim,ylim=ylim,...)
   xylim<-par("usr")
   boxed.labels(xylim[1]-diff(xylim[1:2])/20,
    xylim[3]-diff(xylim[3:4])/10,"Done")
   xy1<-locator(1)
  }
 }
}
zoomInScatterPlot(rnorm(30),rnorm(30))
On Sat, Apr 25, 2020 at 4:40 PM Robert Dodier <robert.dodier at gmail.com> wrote:
#
Many thanks to everyone who contributed to this discussion. It looks
like plotly and dygraphs both work well for zooming plots with
thousands of points (and many other things).

Thanks again, I appreciate your help.

best,

Robert Dodier
On Fri, Apr 24, 2020 at 11:11 AM Robert Dodier <robert.dodier at gmail.com> wrote: