最佳R:填写/图/曲线图与GGPLOT2 shape文件的基础上,regoin的值
我已经下面shape文件是地图佛兰德的(比利时),并且我想绘制它与ggplot 相对于cheapestEnergyPrices。 (因此使用渐变颜色)
head([email protected], n = 1)
OBJECTID Cs012011 Nis_ ... Sec Commune Prov_nl Reg_nl cheapestEnergyPrices mostExpensiveEnergyprices
3 11001A00- 11001 ... A00- AARTSELAAR Antwerpen Vlaanderen 935.03 1254.74
head([email protected], n=1)
[[1]]
An object of class "Polygons"
Slot "Polygons":
[[1]]
An object of class "Polygon"
Slot "labpt":
[1] 4.387485 51.132957
Slot "area":
[1] 6.825956e-05
Slot "hole":
[1] FALSE
Slot "ringDir":
[1] 1
Slot "coords":
[,1] [,2]
[1,] 4.385794 51.13767
[2,] 4.386132 51.13745
... ... ...
[147,] 4.385794 51.13767
Slot "plotOrder":
[1] 1
Slot "labpt":
[1] 4.387485 51.132957
Slot "ID":
[1] "0"
Slot "area":
[1] 6.825956e-05
在这一点上,我已经尝试了很多东西,接下来的一段代码:
> ggplot() + geom_polygon(data = flanders, aes(x = long, y = lat, group = group,fill = flanders$cheapestEnergyPrices))
但不幸的是它会给我的下一个错误代码
Regions defined for each Polygons
Error: Aesthetics must be either length 1 or the same as the data (1224957): x, y, group, fill
然而,当我更换弗兰德$ cheapestEnergyPrices通过,如:
ggplot() + geom_polygon(data = flanders, aes(x = long, y = lat, group = group,fill = 1))
然后我会得到这个不想要的结果,因为一切都包含相同的颜色。
因此......我想我的阴谋与shape文件GGPLOT2,从而polygones是彩色的,相对于例如值cheapestEnergyPrices。 例如,公社这cheapestEnergyPrice最低将有深绿颜色和公社谁是cheapestEnergyPrice要高得多将有一个浅绿色/白色,甚至是红色......
将定义'cheapestEnergyPrices'作为'factor'改变呢? –
这似乎是一个错误:'geom_polygon(data = flanders,aes(...,fill = flanders $ cheapestEnergyPrices))'。由于它位于'aes'内,因此您应该只传递'fill = cheapestEnergyPrices',并且放弃'flanders $'前缀 – arvi1000
...但很难进一步提供帮助,因为无法从您发布的内容重复绘制,而没有shapefile – arvi1000