I am getting an error using geom_map
that I do not get while using geom_polygon
when trying to make a choropleth map.
I am following the ggplot2 documentation as closely as possible.
I have a data.frame of positions plus an id column (lease_number
) to reference later:
dfmap<- read.table(text="id long lat order hole piece group lease_number
1 -90.38103 28.78907 1 FALSE 1 1.1 00016
1 -90.38065 28.82965 2 FALSE 1 1.1 A0016
1 -90.33457 28.82930 3 FALSE 1 1.1 A0016
1 -90.33497 28.78872 4 FALSE 1 1.1 A0016
1 -90.38103 28.78907 5 FALSE 1 1.1 A0016", header=T)
And a data.frame of values with the corresponding id column (just one value here):
df <- data.frame(lease_number="A0016", var1=10)
Following the documentation's structure exactly:
ggplot(df, aes(fill=var1) +
geom_map(aes(map_id=lease_number), map=dfmap) +
expand_limits(dfmap)
Gives the following error:
Error in unit(x, default.units) : 'x' and 'units' must have length > 0
By merging the data like so I can produce a correct plot,
ggplot() +
geom_polygon(data=merge(dfmap, df, by='lease_number', all=T),
aes(x=long, y=lat, group=lease_number, fill=var1))
but I want to avoid this because I will need to reference a lot of different things and it will be much better to be able to reference between two data.frames with the lease_number
column.
I have seen this question but that answer does not apply here since I cannot even get a base map to show up with geom_map
if I remove the fill=
argument. Does anyone know how to take on this error?
Thanks.