Given the following data:
library(tidyverse)
library(sf)
df <- structure(list(geometry = c("LINESTRING (-85.76 38.34, -85.72 38.38)",
"LINESTRING (-85.46 38.76, -85.42 38.76)",
"LINESTRING (-85.89 38.31, -85.89 38.31)"
), var1 = c(4, 5, 6
), var2 = c(1, 2, 3
)), row.names = c(NA, -3L), class = c("tbl_df", "tbl", "data.frame"
))
df
df_sf <- sf::st_as_sf( df, wkt = "geometry" )
# Simple feature collection with 3 features and 2 fields
# geometry type: LINESTRING
# dimension: XY
# bbox: xmin: -85.89 ymin: 38.31 xmax: -85.42 ymax: 38.76
# CRS: NA
# # A tibble: 3 x 3
# geometry var1 var2
# <LINESTRING> <dbl> <dbl>
# 1 (-85.76 38.34, -85.72 38.38) 4 1
# 2 (-85.46 38.76, -85.42 38.76) 5 2
# 3 (-85.89 38.31, -85.89 38.31) 6 3
We can use plot to plot the data including the LINESTRING that has two points at the same location (row = 3):
plot(st_geometry(df_sf), lwd = 10)
giving:
but when we plot it using ggplot the point is dropped:
ggplot() +
geom_sf(data = df_sf, lwd = 8)
Without manually extracting locations that only contain a point, is there a quick way to tell ggplot to plot these? I can see that these points are technically not a line as theres no distance between them but plot is able to pick them up. This question seems related but slightly different, my LINESTRINGs are already created.
thanks





ggplotdefault is not likeplotstackoverflow.com/questions/49887283/…