小编Tde*_*eus的帖子

在sf对象下绘制静态基本映射

我正在尝试在我的sf对象下面绘制一个静态基本地图(用于打印).当ggmap我使用时,我首先得到很多错误,然后我似乎无法弄清楚如何将基本地图链接到我的ggplot2对象geom_sf.

library(sf)
# devtools::install_github("tidyverse/ggplot2")
library(ggplot2)
library(ggmap) 

nc <- st_read(system.file("shape/nc.shp", package="sf"))
nc_map <- get_map(location = "North Carolina, NC", zoom = 7)

ggmap(nc_map)

nc_centers <- st_centroid(nc)

nc_centers %>%
  ggplot() +
  geom_sf(aes(color = SID79, size = BIR74),
          show.legend = "point") +
  coord_sf(datum = NA) +
  theme_minimal()
Run Code Online (Sandbox Code Playgroud)

我也更喜欢使用source = "osm"as样式,但总是会返回'400 Bad Request'.

基地图可能还有另一个好包吗?

gis r geospatial ggmap r-sf

9
推荐指数
3
解决办法
1853
查看次数

如何使用 R 和 dplyr 安排或排序日期

我想在日期列上对我的数据框进行排序。我的示例数据框:

library(tidyverse)    

dates <- tibble(date = c("01-01-2017", "02-03-2017", "01-02-2017", "02-01-2017", "01-03-2017"), 
                   value = c(8, 12, 4, 14, 11)) 
Run Code Online (Sandbox Code Playgroud)

因此,以下内容不起作用,因为它仅在当天进行排序。

arrange(dates, date)
Run Code Online (Sandbox Code Playgroud)

sorting r date

7
推荐指数
1
解决办法
2万
查看次数

sf对象的大小图例不会显示正确的符号

有谁知道为什么sizeaestatic 的传说BIR74不会显示点大小而是矩形?如果答案是肯定的,我该如何解决这个问题?

可重复的例子:

library(sf)
# devtools::install_github("tidyverse/ggplot2")
library(ggplot2)

nc <- st_read(system.file("shape/nc.shp", package="sf"))

nc_centers <- st_centroid(nc)

nc_centers %>%
  ggplot() +
  geom_sf(aes(color = SID79, size = BIR74)) +
  coord_sf(datum = NA) +
  theme_minimal()
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

gis r geospatial ggplot2 r-sf

5
推荐指数
1
解决办法
408
查看次数

在SF对象上设置正确的crs以绘制坐标点

我正在尝试为我的sf对象定义正确的CRS 。我想在以下图层(国家:荷兰)上绘制点:

Simple feature collection with 380 features and 3 fields
geometry type:  MULTIPOLYGON
dimension:      XY
bbox:           xmin: 13565.4 ymin: 306846.2 xmax: 278026.1 ymax: 619232.6
epsg (SRID):    NA
proj4string:    +proj=sterea +lat_0=52.15616055555555 +lon_0=5.38763888888889 +k=0.9999079 +x_0=155000 +y_0=463000 +ellps=bessel +units=m +no_defs
Run Code Online (Sandbox Code Playgroud)

输出:

在此处输入图片说明

该层具有正确的投影。

但是该POINT图层可能没有正确的CRS项目,因为它没有proj4string

Simple feature collection with 566 features and 5 fields
geometry type:  POINT
dimension:      XY
bbox:           xmin: 3.5837 ymin: 50.86487 xmax: 7.120998 ymax: 53.44835
epsg (SRID):    NA
proj4string:    NA
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

如何设置与上一张地图相同的投影,以便可以在其上绘制坐标点?

gis r geospatial map-projections r-sf

5
推荐指数
2
解决办法
2195
查看次数

使用 ISO-8859-1 编码而不是 UTF-8 导出 csv

我在 csv 导出中的编码方面遇到了困难。我来自荷兰,我们使用相当多的 Trema(例如\xc3\xab, \xc3\xaf)和重音符号(例如\xc3\xa9, \xc3\xb3)等。这会在导出到 csv 并在 Excel 中打开文件时出现问题。

\n\n

在 macOS Mojave 上。

\n\n

我已经尝试了多种编码功能,如下所示。

\n\n
library(stringr)\nlibrary(readr)\n\ntest <- c("Argentini\xc3\xab", "Belgi\xc3\xab", "Ha\xc3\xafti")\n\ntest %>%\n  stringi::stri_conv(., "UTF-8", "ISO-8859-1") %>%\n  write.csv2("~/Downloads/test.csv")\n
Run Code Online (Sandbox Code Playgroud)\n\n

但是,这仍然会导致奇怪的字符:

\n\n

在此输入图像描述

\n

r character-encoding stringr

5
推荐指数
1
解决办法
2万
查看次数

如何使用gather()函数指定多个列以整理数据

我想用收集功能整理我的数据但是如何一次指定多个列?

说这是我的数据:

    Country Country.Code Year X0tot4 X5tot9 X10tot14 X15tot19 X20tot24
1  Viet Nam          704 1955   4606   2924     2389     2340     2502
2  Viet Nam          704 1960   5842   4410     2860     2356     2318
3  Viet Nam          704 1965   6571   5646     4328     2823     2335
4  Viet Nam          704 1970   7065   6391     5548     4271     2797
5  Viet Nam          704 1975   7658   6862     6237     5437     4208
6  Viet Nam          704 1980   7991   7473     6754     6113     5266
7  Viet Nam          704 1985   8630   7855     7375     6657     6027 …
Run Code Online (Sandbox Code Playgroud)

transpose r tidyr tidyverse

3
推荐指数
3
解决办法
6600
查看次数

计算一列中从第一年到去年的百分比变化

我想计算第一年2015和最后一年之间的百分比变化,2017作为每个city.

这是我的可重现示例,其中最后一列perct_change_2015_2017是所需的输出。我如何在 R 中为一大堆城市做到这一点?最好在 dplyr 中。

使用正确的百分比变化数字进行编辑

example <- structure(list(city = c("Amsterdam", "Amsterdam", "Amsterdam", 
"Rotterdam", "Rotterdam", "Rotterdam"), year = c(2015L, 2016L, 
2017L, 2015L, 2016L, 2017L), value = c(30L, 35L, 46L, 23L, 19L, 
17L), perct_change_2015_2017 = c(0.5333333333, 0.5333333333, 
0.5333333333, -0.2608695652, -0.2608695652, -0.2608695652)), .Names = c("city", 
"year", "value", "perct_change_2015_2017"), row.names = c(NA, 
-6L), class = c("tbl_df", "tbl", "data.frame"), spec = structure(list(
    cols = structure(list(city = structure(list(), class = c("collector_character", 
    "collector")), year = structure(list(), …
Run Code Online (Sandbox Code Playgroud)

r percentage dplyr

3
推荐指数
1
解决办法
557
查看次数

从下载的文件中提取源元数据

我有一堆我下载的pdf文件。现在我想从文件的元数据中提取下载 url。我如何以编程方式执行此操作?我更喜欢 R 中的解决方案,我正在研究 MacOS Mojave。

如果你想复制你可以[使用这个文件]

在此处输入图片说明

macos metadata r

3
推荐指数
1
解决办法
1035
查看次数

删除具有NA值的行,并在另一年删除这些观察值

我觉得找到合适的词语对我正在努力做的事情有点困难.

说我有这个数据帧:

library(dplyr)

# A tibble: 74 x 3
       country  year conf_perc
         <chr> <dbl>     <dbl>
 1      Canada  2017        77
 2      France  2017        45
 3     Germany  2017        60
 4      Greece  2017        33
 5     Hungary  2017        67
 6       Italy  2017        38
 7      Canada  2009        88
 8      France  2009        91
 9     Germany  2009        93
10      Greece  2009        NA
11     Hungary  2009        NA
12       Italy  2009        NA
Run Code Online (Sandbox Code Playgroud)

现在我想要删除NA2009年具有值的行,但我想在2017年删除这些国家/地区的行.我想得到以下结果:

# A tibble: 74 x 3
       country  year conf_perc
         <chr> <dbl>     <dbl>
 1      Canada …
Run Code Online (Sandbox Code Playgroud)

r dplyr

2
推荐指数
1
解决办法
231
查看次数