如何在地图上使用plotly悬停在点上时创建标签 - R.

时间:2017-06-29 16:25:30

标签: r plot ggplot2 maps plotly

我很困惑如何让我的积分在他们被徘徊时显示信息。目前此代码使我想要显示的值自动显示在地图上,而不是当您将鼠标悬停在点上时。由于有10,000多个数据点,它显示了整个地方的混乱值。我知道plotly是一个库来使这种事情发生但我尝试对库中的代码进行一些小的调整,但都失败了。代码粘贴在下面,以及指向代码生成的图像的链接。请帮助!

library(ggplot2)

library(ggmap)

library(maps)

library(mapdata)

library(geosphere)

library(zoom)

library(ggrepel)

library(plotly)



states <- map_data("state")
regionofInterest<- subset(states, region %in% c("california", "arizona", "new mexico", "texas", "oklahoma","kansas", "missouri", "arkansas", "louisiana", "illinois", "mississippi","indiana", "kentucky", "tennessee", "alabama", "ohio", "west virginia", "virginia", "north carolina", "south carolina", "georgia", "pennsylvania", "delaware", "maryland", "new jersey"))



ggplot(data = regionofInterest) +
 geom_polygon(aes(x = long, y = lat, group = group), fill = "#efede1", color = "black") +

 geom_curve(data=dataset, aes(x = dataset$LNG_BASE, y = dataset$LAT_BASE, xend = dataset$LNG, yend = dataset$LAT), col = "#b29e7d", size = 1, curvature = .2) + 

 geom_point(data=dataset, aes(x = dataset$LNG, y = dataset$LAT), col = "red") + 

 geom_text_repel(data=dataset, aes(x = dataset$LNG, y = dataset$LAT, label = round(dataset$DISTANCE)), col = "black", size = 2, segment.color = NA) + 

theme(panel.background = element_rect(fill="white"), 
 axis.line = element_blank(),
 axis.text.x = element_blank(),
 axis.text.y = element_blank(),
 axis.ticks = element_blank(),
 axis.title.x = element_blank(),
 axis.title.y = element_blank()
 )

IMAGE OF CODE OUTPUT

0 个答案:

没有答案