The locator() function doesn't show as it goes

Trying to use locator in RStudio to get point or line coordinates, and nothing shows up until the locator function is finished.

For example:

plot(1:10)
xy = locator(10, type="l")

then click in the plot. In a standard graphics device window (eg from windows() or X11() (or quartz()? idk) you see the line drawn on each click. But the embedded RStudio graphics window shows nothing until the locator function is finished.

There's a previous Q about this where someone has built a function that loops over locator(1) to get one point, and then you can use lines in the loop to draw between points and these do show up in the graphics window, but that's hard work for something that should work in the graphics window with locator(10, type="l").

I'm using RStudio 2022.02.3 Build 492 on Linux but have heard this is a common problem on other platforms too.

When using Rstudio, you can open the x11 device that supports the locator() functionality that you want to use.

dev.new("x11")
plot(1:10)
xy = locator(10, type="l")

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.