我有两个正在尝试制作的等值线图。第一个工作得很好。但是当我使用不同的value
列复制代码/方法时,图例不会打印。两组代码的区别在于插入scale_fill_brewer()
第二个图。是否使用scale_fill_brewer()
覆盖c$legend
?
例如,这有效:
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
但是,图例中的以下结果为“值”:
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 is green