Phi*_*ood 4 r ggplot2 choropleth r-sf
我试图控制使用在地区分布种类数量sf,ggplot2以及cut_interval()内ggplot2.有时它可以工作,但是对于一些数据集,类别的数量是1.下面是我的代码,输入数据集(7Kb)在这里:
ggplot-test-04.geojson
library(sf)
library(ggplot2)
lga.sf <- st_read("ggplot-test-04.geojson")
ggplot() +
geom_sf(data = lga.sf,
aes(fill = cut_interval(value,5))) +
scale_fill_brewer(palette = "RdYlBu",
name = "Legend" )
Run Code Online (Sandbox Code Playgroud)
在一些数据集中,此代码工作正常.有时我可以选择说n = 6 in cut_interval()来获得5组.但是,我发现经常无法控制等值区域中的群体数量,这对我来说至关重要.到目前为止,我无法判断我的数据是否有问题,我的代码或是否存在软件错误.
在这种情况下,cut_interval()正确执行,但其中一个切割中没有观察到,因此ggplot()忽略它.
(恰好是中间间隔 - 您实际上可以看到第二个和第三个图例项之间的覆盖差距.)
您可以通过查看验证这一点cut_interval()与table():
table(cut_interval(lga.sf$value, 5))
[1.44,1.61] (1.61,1.78] (1.78,1.95] (1.95,2.11] (2.11,2.28]
3 7 0 1 1
Run Code Online (Sandbox Code Playgroud)