Hi all,
I'm having some issues making a choropleth map with geom_map. I don't have a reproducible example, so I realize it may be tough to help me. If I could reproduce the problem, it's likely I could fix it myself, but I'm not even sure where I've gone wrong.
The documentation for geom_map shows this syntax:
ggplot(crimesm, aes(map_id = state)) + geom_map(aes(fill = value), map = states_map) + expand_limits(x = states_map$long, y = states_map$lat) + facet_wrap( ~ variable)
When I run that bit of code the example plots perfect, as expected.
So adapting it to my data frames, I run the following:
m <-ggplot(RegionData1600, aes(map_id = "region"))
m <- m + geom_map(aes(fill = "totals"), map = eurodat_adm1)
m <- m + expand_limits(x = eurodat_adm1$long, y = eurodat_adm1$lat)
(m)
Returning:
Error in unit(x, default.units) : 'x' and 'units' must have length > 0
If I join the two data frames myself, by region, and then plot them using geom_polygon, I get the desired plot. So I'm not quite sure why geom_map is throwing the error. The data.frames are too large for a dput, but I can show you what the first few lines look like below.
For now I'll just use geom_polygon to get my plots, but I thought it might help to raise this issue on the list also.
Thank you,
Jake
> head(RegionData1600)
region quartercentury totals
4561 Baden-Württemberg 1600 1172
4562 Bayern 1600 NA
4563 Berlin 1600 NA
4564 Brandenburg 1600 NA
4565 Bremen 1600 NA
4566 Hamburg 1600 NA
> head(eurodat_adm1)
long lat order hole piece group id region
1 9.650460 49.77634 1 FALSE 1 Baden-Württemberg.1 Germany Baden-Württemberg
2 9.650968 49.76515 2 FALSE 1 Baden-Württemberg.1 Germany Baden-Württemberg
3 9.656839 49.76145 3 FALSE 1 Baden-Württemberg.1 Germany Baden-Württemberg
4 9.640400 49.75014 4 FALSE 1 Baden-Württemberg.1 Germany Baden-Württemberg
5 9.652028 49.74276 5 FALSE 1 Baden-Württemberg.1 Germany Baden-Württemberg
6 9.652208 49.73903 6 FALSE 1 Baden-Württemberg.1 Germany Baden-Württemberg