I want to create a scatterplot on a ggmap with plotly’s hover overs. I’m running into an issue though, where when I convert the ggplot to a plotly object, plotly is adding lines between my points.
My code is here:
lon = c(-84.390099, -84.364393)
lat = c(33.771058, 33.792603)
test = tibble(
Latitude = runif(20, lat[1], lat[2]),
Longitude = runif(20, lon[1], lon[2])
)
base_map <- get_map(location = c(lon = mean(lon), lat = mean(lat)), zoom = 14, maptype = "toner-background")
p <- ggmap(base_map) +
scale_x_continuous(limits = lon, expand = c(0, 0)) +
scale_y_continuous(limits = lat, expand = c(0, 0)) +
geom_point(data=test,
aes(x=Longitude, y=Latitude),
color=I("red"), size=I(2)
)
p
This creates my map:
When I instead use ggplotly to convert the object, I get:
ggplotly(p)
This is problematic both because my map doesn’t show up, and because it’s now connecting the lines. Do you guys know what’s going on?