I'm trying to develop an interactive choropleth in a Shiny application in R. I've tried with plotly, gVis and rCharts, but still without any luck. I need to visualise it for Sweden right now, but I probably need it for other countries as well later on. This is what I have so far for gvisGeoMap:
polygons <- readOGR("/ggshape", layer="SWE_adm1")
polygons <- fortify(polygons, region="ID_1")
data.poly <- as.data.frame(polygons)
data.poly <- data.poly[,c(1,2)]
data.poly.final <- data.frame(locationvar = paste(data.poly[,2],data.poly[,1], sep = ":"),
numvar=1,
hovervar="test")
data.poly.final$locationvar <- as.character(data.poly.final$locationvar)
data.poly.final$hovervar <- as.character(data.poly.final$hovervar)
map <- gvisGeoMap(data=data.poly.final, locationvar = "locationvar",
options=list(width='800px',heigth='500px',colors="['0x0000ff', '0xff0000']",
dataMode = "markers"))
plot(map)
Based on the documentation, I should be able to use lattitude and longitude coordinates as I'm trying here, but I have not been successful yet. The shapefile I'm using is from http://www.gadm.org/download
Basically, does anyone know how to get an interactive visualisation to work with shapefiles from gadm.org?
This is how I would do it with ggplot
SWE <- fortify(polygons, region="ID_1")
SWEplot <- merge(x=SWE, y=my_data, by="id")
p <- ggplot() +
geom_polygon(data = SWEplot , aes(x = long, y = lat, group = group, fill = Patients)) +
geom_path(color="black") +
theme(axis.ticks.y = element_blank(),axis.text.y = element_blank(), # get rid of x ticks/text
axis.ticks.x = element_blank(),axis.text.x = element_blank(), # get rid of y ticks/text
plot.title = element_text(lineheight=.8, face="bold", vjust=1),
panel.background = element_blank(), panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
legend.text=element_text(size=14),
legend.title=element_text(size=16)) + # make title bold and add space
coord_equal(ratio=1)
Which produces
As desired but without the interactivity. What I'm essentially hoping to achieve is something like this http://rcharts.io/viewer/?6735051#.V1px-7t97mE but for Sweden of course.
Given
you could do e.g.
or