I'm having a bit of trouble with my map and was wondering if you guys had any ideas.
I'm trying to create a choropleth map displaying carbon emissions, with overlaying bubbles displaying something called GAIN. However, although every time I add the bubbles into the Shiny code, I lose nearly all visualization of the carbon emissions (see below).
If I reverse the order of my output$map by putting the bubbles before the choropleth fill, I gain back the visualization of the carbon emission data but lose all but 3 of my bubbles?
...#Installing Needed Packages to Run
library(leaflet)
library(tmap)
library(RColorBrewer)
library(rgeos)
library(rgdal)
library(shiny)
library(sp)
install and Process Data
carbontest <-read.csv("carbontest.csv")
Output.Areas<- readOGR(".", "ne_50m_admin_0_countries")
Meshblocktest <- merge(Output.Areas, carbontest, by.x="SOVEREIGNT", by.y="country_name")
#Carbon Emission Point Data
survey.marks <- read.csv("TESTTEST5.csv")
Survey.Points <- SpatialPointsDataFrame(survey.marks[,2:3], survey.marks,proj4string = CRS("+init=EPSG:4167"))
Survey.Points <- spTransform(Survey.Points, CRS("+init=epsg:4167"))
meshblocktesttransform <- spTransform(Meshblocktest, CRS("+init=epsg:4167"))
#The App
ui <- fluidPage(
mainPanel(
leafletOutput("map")
)
)
server <- function(input, output) {
output$map <- renderLeaflet({
tm <- tm_shape(meshblocktesttransform) +tm_fill("CarbonEmissions", palette = "Reds", style = "quantile") +
tm_shape(Survey.Points) + tm_bubbles(size = "GAIN", col = "GAIN", palette = "BuPu", style = "quantile") +
tmap_leaflet(tm)
})
}
shinyApp(ui, server)