Is there a way to make hyperlinks in the pop-up of a tm_bubbles item?
Prior to release 3.3-1 of {tmap}
(March 2021) you had less control over popups in tmap. The world has changed since, and you may consider this answer deprecated - using {leaflet}
directly still works, but it is no longer the only way to make hyperlinks work in popups.
For an example of a purely {tmap}
workflow please see my newer answer.
It is much easier to utilize leaflet library directly, via package leaflet
.
I first paste together the text of the popup as HTML and then use it in leaflet::addCircleMarkers()
calls as popup argument (the tilde is important).
The circle markers from leaflet are very much like tmap bubbles, and can be tuned to look much finer than this; for the sake of brevity of code I have concentrated on the main topic, i.e. customizable hyperlinks in popup balloons of an interactive map.
library(dplyr) # for mutate & pipe
library(tmap) # for the metro dataset
library(leaflet) # interface to leaflet
data("metro") # from the tmap package
metro %>%
mutate(label = paste("marvel at ", name, " and follow <a href = https://stackoverflow.com/>stack overflow</a>")) %>%
leaflet() %>%
addTiles(group = "OSM") %>%
addCircleMarkers(popup = ~label)
Popup on a shape using tmap
In the development version, vector names of popup.vars are now used as labels. Also, I've added popup.format to each layer function. You can specify the number formatting for each variable separately.
data(World, metro)
metro$growth <- (metro$pop2020 - metro$pop2010) / (metro$pop2010 * 10) * 100
ttm()
tm_shape(metro) +
tm_bubbles("pop2010", col = "growth",
border.col = "black", border.alpha = .5,
style="fixed", breaks=c(-Inf, seq(0, 6, by=2), Inf),
palette="-RdYlBu", contrast=1,
title.size="Metro population",
title.col="Growth rate (%)", id="name",
popup.vars=c("Population (2010)"="pop2010", "Population (2020)"="pop2020", "Growth (%)"="growth"),
popup.format=list(growth=list(digits=4)))
R Shiny Leaflet/Mapview map average value on a Choropleth map
This is because your example data is all on the exact same location, there is no reason the mapping function would be expected to average overlapping points. As well if you did you would not have the data from all the different years. I think what you are looking for is clustering, which I don't think is possible in mapview, you can do it with leaflet or tmap though, ex:
output$mapview = renderLeaflet({
Map_data <- Temp_map()
TMAP_MAP <- tm_basemap()+
tm_shape(Map_data)+
tm_dots(clustering=TRUE, col=input$Temp, popup.vars=TRUE)
tmap_leaflet(TMAP_MAP)
})
Related Topics
How to Filter Cases in a Data.Table by Multiple Conditions Defined in Another Data.Table
Create Group Based on Fuzzy Criteria
How to Round Percentage to 2 Decimal Places in Ggplot2
R How Many Element Satisfy a Condition
Change Position of Tick Marks of a Single Graph, Using Ggplot2
Column Name with Brackets or Other Punctuations for Dplyr Group_By
Filtering Single-Column Data Frames
Standard Deviation on Dataframe Does Not Work
How to Change The Character Encoding of .R File in Rstudio
Using Read.Csv.Sql to Select Multiple Values from a Single Column
Manually Defining The Colours of a Wireframe
How to Define "Hidden Global Variables" Inside R Packages
Customise The Infowindow/Tooltip in R -> Plotly
Removing "Nul" Characters (Within R)
Na.Locf and Inverse.Rle in Rcpp