我有一个简单的问题,但仍然不知道如何找到答案。我所需要的只是为传单地图添加一个标题。我不需要它在地图上,就在它上面,就像在通常的 ggplot 地图中一样。
我的代码是:
map <- leaflet(data_counts) %>%
addTiles() %>%
addCircleMarkers(lng=data_counts$Long, lat=data_counts$Lat,
color="#2c4f54", fillOpacity=0.6,
stroke = FALSE,
radius=~sqrt(NumObs)/pi*10,
label=~paste(data_counts$`Birth place...14`), labelOptions = labelOptions(noHide = F))
我尝试了不同的选择,但仍然没有成功
不确定您是否已经找到解决方案,但您可以尝试以下方法:
library(leaflet)
library(tidyverse)
library(htmltools)
tag.map.title <- tags$style(HTML("
.leaflet-control.map-title {
transform: translate(50%,50%);
position: fixed !important;
left: 45%;
text-align: center;
padding-left: 10px;
padding-right: 10px;
background: rgba(255,255,255,0.75);
font-weight: bold;
font-size: 28px;
}
"))
title <- tags$div(
tag.map.title, HTML("This is the Title")
)
map <- leaflet(data_counts) %>%
addTiles() %>%
addCircleMarkers(lng=data_counts$Long, lat=data_counts$Lat,
color="#2c4f54", fillOpacity=0.6,
stroke = FALSE,
radius=~sqrt(NumObs)/pi*10,
label=~paste(data_counts$`Birth place...14`), labelOptions =
labelOptions(noHide = F)) %>%
addControl(title, position = "topleft", className="map-title")