- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
试图结合 geom_sf()
与其他一些几何体。我需要反转 y 轴以使绘图正确显示。然而,geom_sf()
似乎忽略了 scale_y_reverse()
.
例子:
# install the dev version of ggplot2
devtools::install_github("tidyverse/ggplot2")
library(ggplot2)
library(sf)
library(rgeos)
library(sp)
# make triangle
tmpdf <- data.frame(id = 1,
geom = c("LINESTRING(10 10,-10 10,0 0,10 10)"), stringsAsFactors = F)
# read WKT polygons into 'sp' SpatialPolygons object
tmpdf$spgeom <- lapply(tmpdf$geom, FUN = function(x) readWKT(x))
# extract coordinates from the linestring (there has got to be a better way to do this...)
test <- tmpdf[1,"spgeom"]
test2 <- sapply(test, FUN=function(x) x@lines)
test3 <- sapply(test2, FUN=function(x) x@Lines)
test4 <- lapply(test3, FUN=function(x) x@coords)
# plot the sp coordinates
ggplot() +
geom_point(data=data.frame(test4[[1]]), aes(x,y), color="blue") +
geom_path(data=data.frame(test4[[1]]), aes(x=x, y=y), color="blue") +
coord_fixed()
# make an 'sf' sfc_POLYGON object
tmpdf$sfgeom <- st_as_sfc(tmpdf$geom)
## plot both together, they overlap
ggplot() +
geom_point(data=data.frame(test4[[1]]), aes(x,y), color="blue") +
geom_path(data=data.frame(test4[[1]]), aes(x=x, y=y), color="blue") +
coord_fixed() +
geom_sf(data=tmpdf, aes(geometry=sfgeom), color="red")
Coordinate system already present. Adding new coordinate system, which will replace the existing one.
## plot with scale reverse, and everything but the geom_sf flips.
ggplot() +
geom_point(data=data.frame(test4[[1]]), aes(x,y), color="blue") +
geom_path(data=data.frame(test4[[1]]), aes(x=x, y=y), color="blue") +
coord_fixed() +
geom_sf(data=tmpdf, aes(geometry=sfgeom), color="red") +
scale_y_reverse()
Coordinate system already present. Adding new coordinate system, which will replace the existing one.
coord_sf(ylim=-(range(st_coordinates(tmpdf$sfgeom)[,"Y"])))
最佳答案
啊哈!这是一个解决方法:
## get the geom coordinates as data.frame
geomdf <- st_coordinates(tmpdf$sfgeom)
## reverse Y coords
geomdf[,"Y"] <- geomdf[,"Y"]*-1
## re-create geom
tmpdf$sfgeom2 <- st_as_sfc(st_as_text(st_linestring(geomdf)))
## plot the reversed y-coordinate geom:
ggplot() +
geom_point(data=data.frame(test4[[1]]), aes(x,y), color="blue") +
geom_path(data=data.frame(test4[[1]]), aes(x=x, y=y), color="blue") +
coord_fixed() +
geom_sf(data=tmpdf, aes(geometry=sfgeom2), color="red") +
scale_y_reverse()
关于r - 如何在 geom_sf() 中翻转 y 轴?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53620768/
我有一张印度的基本 map ,其中包含州和边界、一些标签以及存储为 gg 对象的许多其他规范。我想生成一些带有区域图层的 map ,这些 map 将包含来自不同变量的数据。 为了防止地区 map 覆盖
我正在尝试修剪 ggplot 中的空白区域使用 geom_sf() 创建的 map 。我发现有多个资源讨论在使用 ggsave() 保存绘图时删除空白。不过,我希望无需保存即可删除空白区域。 使用 g
我有几个包含各种公共(public)交通路线的空间形状文件,我想使用 ggplot2 和 sf 库制作 map 。这里的问题是我手动为一些特定路线分配颜色,但我无法设法向绘图添加图例。 知道如何使用g
我正在 ggplot 中处理多个 sf 几何图形,并希望以点、线和正方形(对于多边形)的形式显示图例。然而,geom_sf图例结合了我的几何特征(即结合线和点)如下所示: library(ggplot
我正在使用 geom_sf 和 ggplot 绘制点,并且想更改点的形状。我可以在 map 上更改它们,但图例从不反射(reflect)点的形状,即使使用 override.aes 也是如此。 我不知
当使用 ggplot/geom_sf 绘制 map 时,任何映射到美学的图层都会在图例中表示。我也知道使用 show.legend = ... 可用于强制图例表示和操纵所使用的符号系统(点、线、多边形
使用 geom_sf 绘图时,去除网格线的标准方法似乎是徒劳的。 . 例如,如果我们绘制一个简单的 ggplot对象,这可以删除网格 library(tidyverse) library(sf) mt
在绘制基本世界地图时,我没有得到显示在坐标轴上的纬度和长度。我已经在 cran 上完成了 geom_sf() 提供的示例,并且确实显示了纬度。 这是我下面的代码。 library("ggplot2")
关闭。这个问题需要debugging details .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 4年前关闭。 Improve this question 我尝
有没有人知道如何使用 ggplot2 根据事件的发生绘制内核密度图?和 sf ? 例如,考虑 meuse来自 sp 的数据集包(让我们假设每个点都是一个事件发生) library(sf) librar
我正在使用 Tigris 包下载带有代码的形状文件, options(tigris_class = "SF") 虽然我可以轻松地映射多边形 ggplot(data=zctas) + geom_sf
我有一个 shapefile,my_sf。如果我写: ggplot() + geom_sf( data = my_sf, size = 0.5 # this is the defa
我正在尝试使用 naturalearth 数据和 ggplot2 获取世界地图。但是,世界地图的 x 轴上没有显示经纬网和坐标轴刻度线和标签。据我所知,这个问题曾经用 coord_sf(expand
我目前在 Windows 上运行 R 版本 3.4.2,并且有 ggplot2(通过 tidyverse)和 sf 包版本 3.4.2。我正在尝试使用 ggplot2 sf 套件映射空间数据。 尝试运
我想使用 ggplot2::geom_sf 绘制带有多个小 map 的图形.这里的挑战是如何做到这一点,使所有 map 都在图像中居中并处于相同的空间尺度。这是问题(以下可重现示例的数据): 使用 f
有没有办法用geom_sf改变alpha?此示例来自 ?geom_sf 中的示例。我尝试添加 alpha=.2 ,但它似乎忽略了这种美感,尽管 alpha 是 geom_line 可接受的美感。它不会
以下将 scale_x_continuous 与 geom_sf 结合使用可完全删除 x 轴标签。我假设指定的中断实际上并不存在于 ggplot 对象中,因此根本不会显示任何中断。 这是由coord_
我正在尝试使用 ggplot2 中的 sf 和 geom_sf 制作 map ,其中一组点数据使用连续颜色比例(-1 到 1),一组线数据使用离散比例(a、b、c、d)着色。但是,当我在同一张 map
试图结合 geom_sf()与其他一些几何体。我需要反转 y 轴以使绘图正确显示。然而,geom_sf()似乎忽略了 scale_y_reverse() . 例子: # install the dev
我正在使用 ggplot 和 geom_sf 制作 map ,我想为图例中的值添加逗号。我发现编辑颜色条的唯一方法是通过“指南”,但是 + guides(fill = guide_colorbar(l
我是一名优秀的程序员,十分优秀!