i have 2 choropleth maps attempting make. first 1 has worked fine. when replicate code/method using different value
column, legend not print. difference between 2 sets of code lies in inserting scale_fill_brewer()
second plot. using scale_fill_brewer()
overriding c$legend
?
for example, works:
head(ra, 5) region value 1 alabama 106 2 california 622 3 colorado 22 4 connecticut 86 5 delaware 43 str(ra) 'data.frame': 51 obs. of 2 variables: $ region: chr "alabama" "california" "colorado" "connecticut" ... $ value : num 106 622 22 86 43 7 232 19 10 121 ... c = statechoropleth$new(ra) c$legend = "# of stores" c$set_num_colors(4) c$set_zoom(null) c$show_labels = false without_abbr = c$render() without_abbr
but, following results in "value" in legend:
head(ra, 5) region value 1 alabama 5.8703474 2 alaska 0.4880526 3 arizona 4.8851831 4 arkansas 2.7045759 5 california 35.2607419 > str(ra) 'data.frame': 51 obs. of 2 variables: $ region: chr "alabama" "alaska" "arizona" "arkansas" ... $ value : num 5.87 0.488 4.885 2.705 35.261 ... c = statechoropleth$new(ra) c$title = "total sales" c$legend = "$ billions" c$set_num_colors(4) c$set_zoom(null) c$show_labels = false without_abbr = c$render() without_abbr + scale_fill_brewer(palette=2) # palette 2 green
thank using choroplethr.
try this:
without_abbr + scale_fill_brewer(name="legend title", palette=2)
the issue how ggplot2 handles legends (scales). have option of manually naming scale/legend name
parameter. otherwise, looks uses name of column.
Comments
Post a Comment