【发布时间】:2020-10-29 09:49:04
【问题描述】:
我有一个几何类型为“MULTILINESTRING”的简单特征集合(线),我想用 ggplot2 进行绘图。线条粗细应该代表一个字段的值。不幸的是,我无法提供代表。但也许有一个很容易识别的明显错误。
lines
输出:
Simple feature collection with 171 features and 1 field
geometry type: MULTILINESTRING
dimension: XY
bbox: xmin: 579649.7 ymin: 5801899 xmax: 625387 ymax: 5851019
projected CRS: ETRS89 / UTM zone 32N
First 10 features:
strahler geometry
1 1 MULTILINESTRING ((580016.3 ...
2 1 MULTILINESTRING ((582188.7 ...
3 1 MULTILINESTRING ((581499.9 ...
4 1 MULTILINESTRING ((586581.9 ...
5 1 MULTILINESTRING ((584296.4 ...
6 1 MULTILINESTRING ((583833.5 ...
7 1 MULTILINESTRING ((584608.8 ...
8 1 MULTILINESTRING ((583096.1 ...
9 1 MULTILINESTRING ((588869.2 ...
10 1 MULTILINESTRING ((587474.7 ...
我正在绘制它
lines %>%
mutate(strahler = as.integer(strahler)) %>%
ggplot() +
geom_sf(aes(size = strahler))
结果看起来真的很乱。似乎以这种方式使用大小会影响线条的顶点。
代表
当我尝试提供 reprex 时,并没有出现这种凌乱的外观
lines <-
tibble(
x = c(1, 2, 5, 2, 4),
y = c(0, 3, 4, 3, 2),
order = c(2L, 2L, 2L, 1L, 1L)
) %>%
st_as_sf(coords = c("x", "y")) %>%
st_sf(crs = 25832) %>%
group_by(order) %>%
summarise() %>%
st_cast("MULTILINESTRING")
lines
Simple feature collection with 2 features and 1 field
geometry type: MULTILINESTRING
dimension: XY
bbox: xmin: 1 ymin: 0 xmax: 5 ymax: 4
projected CRS: ETRS89 / UTM zone 32N
# A tibble: 2 x 2
strahler geometry
<int> <MULTILINESTRING [m]>
1 1 ((2 3, 4 2))
2 2 ((1 0, 2 3, 5 4))
绘制它
lines %>%
mutate(strahler = as.integer(strahler)) %>%
ggplot() +
geom_sf(aes(size = strahler))
我想这与看起来不同的几何字段有关,但我不知道如何转换它。我很高兴任何提示!
【问题讨论】:
-
看看这个可能的解决方案:stackoverflow.com/a/54613325/7547327
-
@mrhellmann:谢谢,但我以前见过这个问题,并没有帮助我解决这个问题!
-
尝试在对“geom_sf”的调用中设置参数“lineend =”和/或“linejoin =”。选项分别为“圆形、对接、方形”和“圆形、斜接和斜角”。我会从“圆形”开始。