gglocator: Locator for ggplots.

Description Usage Arguments Value Author(s) Examples

View source: R/gglocator.R

Description

Locator for ggplots. (Note : only accurate when extent = "normal" when using ggmap.)

Usage

1
2
gglocator(n = 1, message = FALSE, xexpand = c(0, 0), yexpand = c(0, 0),
  mercator = TRUE)

Arguments

n

number of points to locate.

message

unused

xexpand

expand argument in scale_x_continuous

yexpand

expand argument in scale_y_continuous

mercator

logical flag; should the plot be treated as using the projection common to most web map services? Set to FALSE if the axes on the plot use a linear scale.

Value

a data frame with columns according to the x and y aesthetics

Author(s)

Tyler Rinker with help from Baptiste Auguie and StackOverflow user DWin with additions and canning by David Kahle david.kahle@gmail.com. Updated by \@Nikolai-Hlubek and \@mvkorpel.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
if(interactive()){

# only run for interactive sessions
df <- expand.grid(x = 0:-5, y = 0:-5)
p <- qplot(x, y, data = df) +
  annotate(geom = "point", x = -2, y = -2, colour = "red")
print(p)
cat("click red point\n")
print(pt <- gglocator(mercator = FALSE))
p2 <- last_plot() +
  annotate("point", pt$x, pt$y, color = "blue", size = 3, alpha = .5)
cat("a blue point should appear where you clicked\n")
print(p2)

p3 <- p +
  scale_x_continuous(expand = c(0,0)) +
  scale_y_continuous(expand = c(0,0))
print(p3)
cat("click any point\n")
print(gglocator(1, xexpand = c(0,0), yexpand = c(0,0),
                mercator = FALSE))


}

fresques/ggmap documentation built on May 28, 2019, 8:40 p.m.