16

Is there a way to enable locator() functionality in the RStudio plot zoom? This only works in the smaller window (default bottom right) of RStudio but when you click on a viewer already open as a separate window, no coordinates are captured:

plot(iris$Petal.Width, iris$Petal.Length)
locator()

Perhaps the answer here is that is not currently implemented and that is why I couldn't find mention of it online.

I'm using RStudio version 0.99.491.

Thanks in advance.

boshek
  • 4,100
  • 1
  • 31
  • 55
  • 1
    it works with x11 : `x11(); plot(1:4); locator(1)` what os are you using? I assume windows since the answer below would be irrelevant if you were not using windows.. also works with `quartz(); plot(1:4); locator(1)`. quartz works flawlessly with n given or missing. x11 seems finicky with n missing but doesnt crash if you are patient on the escape – rawr Jan 22 '16 at 03:26

1 Answers1

1

This does not directly use RStudio's "Zoom" function, but gets pretty close at what you're probably after:

df <- data.frame(1:4)
windows()
plot(df)
locator(1)

A couple of notes:

  1. You can't dynamically resize the window. If you want to zoom in, you first need to call windows(), then resize the window, then execute plot(df).
  2. Be careful to specify the n argument for locator(). Otherwise it will crash your R session because of this bug. (Which hasn't been resolved AFAIK)

But if your purpose is to be able to use locator() on a zoomed version of a plot (i.e. if you have a very crowded plot), this should do the trick.

Felix
  • 1,611
  • 13
  • 22
  • 1
    Sorry. The whole crash R studio session is a bit of deal breaker here. – boshek Jan 21 '16 at 17:36
  • Yep, that's what I thought. It's annoying. Maybe file an issue with RStudio or contact their support that this bug is still exists and needs to be fixed. – Felix Jan 21 '16 at 17:54
  • 1
    This is insofar a pretty relevant bug, given that together with the `zoom()` package you would be able to combine `zm()` and `locator()` and create a pretty effective instrument to visually picking out individual data points. But since `zoom()` essentially creates another `windows()` instance, this also leads to a session crash (at least on my machine). But maybe this functionality will be added to the `manipulate()`package in the future. Anyway, I think it's a good question. – Felix Jan 21 '16 at 18:03
  • In 2021 on my M1 macbook air when I specify `locator(n=5)` it always crashes, but when I just run `locator()` it works. So the opposite of what used to be the case it seems like... – Ricky Dec 29 '21 at 15:24