我有一张使用Leaflet的地图,它在r markdown的html输出中有效,但是当我在Google或IE中打开html时,地图不会渲染。 Ggmap工作正常,但我更喜欢交互式地图。有什么想法吗?
```{r setup, include=FALSE}
knitr::opts_chunk$set(
echo = FALSE,
warning = FALSE,
message = FALSE,
comment=NA,
fig.height=7,
fig.width = 9)
```
```{r Libraries}
library(leaflet)
library(ggmap)
```
Plot map with leaflet package.
```{r Leaflet}
#using leaflet
Pin <- data.frame(t(c(ID=1,Lat=-27.474176,Lng=153.024901)))
Bne2 <- leaflet() %>%
addTiles() %>%
addMarkers(data=Pin)
Bne2
```
Plot map with ggmap package.
```{r Ggmap}
#using ggmap
Sa2 <- data.frame(t(c(ID=1,Lat=-27.474176,Lng=153.024901)))
Brisbane <- get_map("Brisbane,Australia",zoom=11)
BNE <- ggmap(Brisbane)+
geom_point(data=Sa2,aes(x=Lng,y=Lat),color="black",size=3)
plot(BNE)
```
答案 0 :(得分:1)
我看到同样的问题,似乎与浏览器中未呈现的默认图块有关。但是,我不知道为什么会这样。
所以有几个选项
```{r Libraries}
library(leaflet)
library(ggmap)
library(googleway)
```
Plot map with leaflet package.
```{r Leaflet}
#using leaflet
Pin <- data.frame(t(c(ID=1,Lat=-27.474176,Lng=153.024901)))
Bne2 <- leaflet() %>%
addTiles(urlTemplate = 'http://{s}.tile.opentopomap.org/{z}/{x}/{y}.png') %>%
addMarkers(data=Pin)
Bne2
```
Plot map with ggmap package.
```{r Ggmap}
#using ggmap
Sa2 <- data.frame(t(c(ID=1,Lat=-27.474176,Lng=153.024901)))
Brisbane <- get_map("Brisbane,Australia",zoom=11)
BNE <- ggmap(Brisbane)+
geom_point(data=Sa2,aes(x=Lng,y=Lat),color="black",size=3)
plot(BNE)
```
Plot map with googleway
```{r googleway}
## you need an api key to use google maps
mapKey <- 'your_api_key'
google_map(key = mapKey) %>%
add_markers(data = Pin)
```
这三个人都在Chrome中工作