【问题标题】:R - Can't customize values of cuts when plotting points with spplotR - 使用 spplot 绘制点时无法自定义切割值
【发布时间】:2017-11-29 20:58:15
【问题描述】:

我正在使用 spplot 来绘制 shapefile。我需要根据shapefile的属性值给shapefile的每个点赋予不同的颜色。

我的 shapefile 属性表如下所示: Attribute_Table。我必须根据秋季,冬季,春季和夏季的值来绘制点(我总共有4个地块,每个季节1个)。

通过运行此代码(r_values 是我的 shapefile):

# Defining point size
point_size = 0.8

# Defining where cuts are
classes_R = seq(-1,1,0.05)

# Defining color of scale bar
my.palette_R = brewer.pal(n = 10, name = "RdBu")

spplot(r_values, zcol = c("Fall","Winter","Spring","Summer"), do.log = F,as.table = T,
   pch = 20, cex = point_size, key.space = "right", col.regions = my.palette_R,
   main = "R Values - P Model", colorkey = T, at=classes_R,
   sp.layout=(list(new_layer_1,new_layer_2))) #sp.layout is for 2 other layers (you can see the states in gray and the lakes in blue in backround

我得到这个情节:Plot

更改 classes_R 中的切割(类)不会更改结果图。

我想要获得的是每 0.05 个从 -1 到 +1 的切割的地图,以及带有这些切割的比例尺右侧的标签。

这里是下载包含一些数据的 excel 文件的链接。这是一个包含点坐标的数据框

https://drive.google.com/open?id=1WPyS5TFGCxBDNhJIJc_jKvFmJd5hthl4

【问题讨论】:

  • 能否请您提供一个小型测试数据集的访问权限,以便我们重现您的代码?此外,如果您希望在 2 范围内削减 0.05,则需要 40 种颜色。看看herehere 看看它是否回答了您的问题。
  • @Kamil 我添加了一个excel文件,里面有一些数据和每个点的坐标

标签: r plot customization shapefile


【解决方案1】:

答案在“ssplot”的 R 文档中。它说:

cuts:切割的数量,或者,对于 SpatialPointsDataFrame 类的对象,实际使用的切割

所以在这种情况下,“cuts”不是表示切割数量的整数,而是包含要使用的实际切割的向量。

我使用选项“cuts”而不是“at”更改了代码,它起作用了。

【讨论】:

    猜你喜欢
    • 2018-01-17
    • 1970-01-01
    • 1970-01-01
    • 2014-01-06
    • 1970-01-01
    • 1970-01-01
    • 2012-05-09
    • 1970-01-01
    • 2020-12-27
    相关资源
    最近更新 更多