使用R Studio悬停散点图

时间:2015-07-10 17:47:04

标签: r google-maps rstudio ggmap

我有一个R程序,想要一种将鼠标悬停在数据点上并显示信息的方法。我一直试图使用传单,但它太复杂了。 No matter what I try, OpenStreetMap doesn't load in R Studio.

我正在寻找简单的方法让人们将鼠标悬停在数据点上以查看信息。此代码显示以下图像:

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

1 个答案:

答案 0 :(得分:1)

R有一个新的leaflet包,它非常易于使用,可以满足您的需求。请参阅我的rPubs帖子,其中我将完成步骤here并包含演示地图。