Rhonda
Rhonda

Reputation: 1721

Hover-over scatterplot using R Studio

I have an R program and would like a way to hover over the data point and display information. I've been trying to use leaflet, but it's so complicated. No matter what I try, OpenStreetMap doesn't load in R Studio.

I'm just looking for simple way to allow person to hover over datapoint to see information. This code displays the image below:

library(ggmap)
library(ggplot2)

...


# create a new grouping variable

sep$Percent_SEP12_Assets <- ifelse(sep[,8] <= 33, "Less than 33%", ifelse(sep[,8] >= 66, "More than 66%", "Between 33% and 66%"))
sep$Percent_SEP12_Assets <- factor(sep$Percent_SEP12_Assets,
                               levels = c("More than 66%", "Between 33% and 66%", "Less than 33%"))


# get the map
bbox <- make_bbox(sep$Longitude, sep$Latitude, f = 1)
map <- get_map(bbox)


# plot the map and use the grouping variable for the fill inside the aes
ggmap(map) +
  geom_point(data=sep, aes(x = Longitude, y = Latitude, color=sep$Percent_SEP12_Assets ), size=9, alpha=0.6) +
  scale_color_manual(values=c("green","orange","red"), drop = FALSE)

map

Upvotes: 0

Views: 763

Answers (1)

jtdoud
jtdoud

Reputation: 136

R has a new leaflet package that is totally easy to use and should get you what you need. See my rPubs post where I walk through the steps here and include a demo map.

Upvotes: 1

Related Questions