小编pom*_*mus的帖子

如何在 R 中合并两个地图?

我在下面提供了示例代码。我的问题涉及将“map2”放置在“map1”左上角的正方形中,并添加从“map2”到“map1”上特定位置的箭头。我搜索了该网站,但最常讨论的主题与合并两个数据层有关。

library (tidyverse)
  library (rnaturalearth)
  world <- rnaturalearth::ne_countries(scale = "medium", returnclass = "sf")

  map1<- ggplot(data = world) +
    geom_sf() +
    #annotation_scale(location = "bl", width_hint = 0.2) +
    #annotation_north_arrow(location = "tr", which_north = "true",
    #                     pad_x = unit(0.83, "in"), pad_y = unit(0.02, "in"),
    #                   style = north_arrow_fancy_orienteering) +
    coord_sf(xlim = c(35, 48), ylim=c(12, 22))+
    xlab("Longtitude")+
    ylab("Latitude")


  map2<- ggplot(data = world) +
    geom_sf() +
    #annotation_scale(location = "bl", width_hint = 0.2) +
    #annotation_north_arrow(location = "tr", which_north = "true",
    #                     pad_x = unit(0.83, "in"), …
Run Code Online (Sandbox Code Playgroud)

maps plot r ggplot2

10
推荐指数
6
解决办法
1089
查看次数

错误:dyn.load(file, DLLpath = DLLpath, ...) 中的“gmm”的包或命名空间加载失败:无法加载共享对象

我已将 R 版本上传到 4.0.2 (2020-06-22)。\n安装 gmm 包后,当我需要它时,我收到以下消息。我还为其他软件包(例如 TropFishR)采纳了此消息。我有 Xcode 10.3 。我重新安装了R studio和R几次。非常感谢您的宝贵时间。

\n

错误信息:

\n
Error: package or namespace load failed for \xe2\x80\x98gmm\xe2\x80\x99 in dyn.load(file, DLLpath = DLLpath, ...):\n unable to load shared object '/Library/Frameworks/R.framework/Versions/4.0/Resources/library/gmm/libs/gmm.so':\n  dlopen(/Library/Frameworks/R.framework/Versions/4.0/Resources/library/gmm/libs/gmm.so, 6): Library not loaded: /usr/local/gfortran/lib/libgomp.1.dylib\n  Referenced from: /Library/Frameworks/R.framework/Versions/4.0/Resources/library/gmm/libs/gmm.so\n  Reason: image not found\n\n\nsession info:\n\n version 4.0.2 (2020-06-22)\nPlatform: x86_64-apple-darwin17.0 (64-bit)\nRunning under: macOS Mojave 10.14.6\n\nMatrix products: default\nBLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib\nLAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib\n\nlocale:\n[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8\n\nattached base packages:\n[1] stats     graphics  grDevices utils    \n[5] datasets  methods   base     \n\nother attached packages:\n[1] sandwich_2.5-1\n\nloaded via a namespace …
Run Code Online (Sandbox Code Playgroud)

r

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

从长格式重塑为宽格式时,pivot_wider 会引入 NA 值

当我使用 重塑数据时遇到问题pivot_wider()

我的数据如下所示:

df <- data.frame(area = c( "Area1","Area1","Area1","Area2","Area2","Area2","Area3","Area3","Area3"),
                   species = c("species1","species2","species3","species1","species2","species3","species1","species2","species3"),
                   season= c("Season1","Season1","Season1","Season2","Season2","Season2","Season3","Season3","Season3"),
                   value= c(2,3,5,7,9,2,6,9,3))
Run Code Online (Sandbox Code Playgroud)

我可以将数据框更改为宽格式,如下所示。

df_wide <- df %>%
  mutate(row = row_number()) %>%
  pivot_wider(id_cols= c(row,species),
              ,names_from = "season",
              values_from = "value") %>%
  select(-row)
Run Code Online (Sandbox Code Playgroud)

这是输出的数字。

在此输入图像描述

我的问题是它引入了 NA,因为pivot_wider()为每个值创建一个新列。

在此输入图像描述

如果你帮助我,我会很棒...

r tidyverse

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

标签 统计

r ×3

ggplot2 ×1

maps ×1

plot ×1

tidyverse ×1