如何将特定状态按组与R中的ggplot2中的一个标签合并在一起?

2023-12-26

我想绘制美国的电网地图,所以我需要将特定的州合并在一起。我想为这些状态绘制边界,但它不起作用。每组也只有一个标签。这是我的数据:[https://iastate.box.com/s/12xru62lvmbbkrohsn7b4wwexq11umn7] 这是我的代码:

# Join and arrange
 states <- us_map(exclude = c("AK", "HI"))
 states_data <- left_join(states, myinput, by = c("abbr" = "region")) |> 
 arrange(emission, growth, group, order)

ggplot(states_data, aes(x, y, fill = value, group = group, subgroup = grid)) +
geom_polygon()+
scale_fill_continuous(low = "white", high = "red", name = "Ele gen (EJ)", label = 
scales::comma) +
facet_grid(emission~growth) +
coord_equal() +
ggthemes::theme_map() +
theme(legend.position = "bottom")+
geom_text(aes(x, y, label = grid),size = 5,family = "serif",
        data = states_data, vjust = 1.2, nudge_y = -100000,check_overlap = T)+
geom_polygon(aes(color = "Border", group=grid),fill = NA,color = "black")

And this the output which is not what I have in my mid: enter image description here

I want to plot these regions (plus borders to specify because I can't show them with different color) enter image description here

data

structure(list(region = c("AL", "AR", "AZ", "CA", "CO", "CT", 
"DC", "DE", "FL", "GA", "IA", "ID", "IL", "IN", "KS", "KY", "LA", 
"MA", "MD", "ME", "MI", "MN", "MO", "MS", "MT", "NC", "ND", "NE", 
"NH", "NJ", "NM", "NV", "NY", "OH", "OK", "OR", "PA", "RI", "SC", 
"SD", "TN", "TX", "UT", "VA", "VT", "WA", "WI", "WV", "WY", "AL", 
"AR", "AZ", "CA", "CO", "CT", "DC", "DE", "FL", "GA", "IA", "ID", 
"IL", "IN", "KS", "KY", "LA", "MA", "MD", "ME", "MI", "MN", "MO", 
"MS", "MT", "NC", "ND", "NE", "NH", "NJ", "NM", "NV", "NY", "OH", 
"OK", "OR", "PA", "RI", "SC", "SD", "TN", "TX", "UT", "VA", "VT", 
"WA", "WI", "WV", "WY", "AL", "AR", "AZ", "CA", "CO", "CT", "DC", 
"DE", "FL", "GA", "IA", "ID", "IL", "IN", "KS", "KY", "LA", "MA", 
"MD", "ME", "MI", "MN", "MO", "MS", "MT", "NC", "ND", "NE", "NH", 
"NJ", "NM", "NV", "NY", "OH", "OK", "OR", "PA", "RI", "SC", "SD", 
"TN", "TX", "UT", "VA", "VT", "WA", "WI", "WV", "WY", "AL", "AR", 
"AZ", "CA", "CO", "CT", "DC", "DE", "FL", "GA", "IA", "ID", "IL", 
"IN", "KS", "KY", "LA", "MA", "MD", "ME", "MI", "MN", "MO", "MS", 
"MT", "NC", "ND", "NE", "NH", "NJ", "NM", "NV", "NY", "OH", "OK", 
"OR", "PA", "RI", "SC", "SD", "TN", "TX", "UT", "VA", "VT", "WA", 
"WI", "WV", "WY"), value = c(6.22256321333333, 6.22256321333333, 
2.20794523906666, 1.49034165333333, 2.20794523906666, 0.826546816817333, 
2.61905459786667, 2.61905459786667, 1.65110329, 6.22256321333333, 
1.59528739166667, 3.0363665376, 3.13763399333332, 3.865420576, 
0.790624669333333, 3.865420576, 6.22256321333333, 0.826546816817333, 
2.61905459786667, 0.826546816817333, 3.865420576, 1.59528739166667, 
3.13763399333332, 6.22256321333333, 3.0363665376, 6.22256321333333, 
1.59528739166667, 1.59528739166667, 0.826546816817333, 2.61905459786667, 
2.20794523906666, 3.0363665376, 1.21040939333333, 3.865420576, 
0.790624669333333, 3.0363665376, 2.61905459786667, 0.826546816817333, 
6.22256321333333, 1.59528739166667, 6.22256321333333, 3.50149982333333, 
3.0363665376, 6.22256321333333, 0.826546816817333, 3.0363665376, 
3.13763399333332, 3.865420576, 2.20794523906666, 6.58823506033333, 
6.58823506033333, 2.33729970666667, 1.35043392, 2.33729970666667, 
0.7918773089276, 2.64941819863333, 2.64941819863333, 1.84968858666667, 
6.58823506033333, 1.69423596966667, 2.82831107136667, 3.22375391666666, 
4.14114214399999, 0.816646300333333, 4.14114214399999, 6.58823506033333, 
0.7918773089276, 2.64941819863333, 0.7918773089276, 4.14114214399999, 
1.69423596966667, 3.22375391666666, 6.58823506033333, 2.82831107136667, 
6.58823506033333, 1.69423596966667, 1.69423596966667, 0.7918773089276, 
2.64941819863333, 2.33729970666667, 2.82831107136667, 1.15469864333333, 
4.14114214399999, 0.816646300333333, 2.82831107136667, 2.64941819863333, 
0.7918773089276, 6.58823506033333, 1.69423596966667, 6.58823506033333, 
3.66557223, 2.82831107136667, 6.58823506033333, 0.7918773089276, 
2.82831107136667, 3.22375391666666, 4.14114214399999, 2.33729970666667, 
6.72966092166666, 6.72966092166666, 2.3737108016, 1.58503659, 
2.3737108016, 0.884016546345666, 2.8041352651, 2.8041352651, 
1.73653393333333, 6.72966092166666, 1.73917558366667, 3.23410557176666, 
3.34795298333333, 4.19485727566666, 0.859289106, 4.19485727566666, 
6.72966092166666, 0.884016546345666, 2.8041352651, 0.884016546345666, 
4.19485727566666, 1.73917558366667, 3.34795298333333, 6.72966092166666, 
3.23410557176666, 6.72966092166666, 1.73917558366667, 1.73917558366667, 
0.884016546345666, 2.8041352651, 2.3737108016, 3.23410557176666, 
1.28265139333333, 4.19485727566666, 0.859289106, 3.23410557176666, 
2.8041352651, 0.884016546345666, 6.72966092166666, 1.73917558366667, 
6.72966092166666, 3.79724887666667, 3.23410557176666, 6.72966092166666, 
0.884016546345666, 3.23410557176666, 3.34795298333333, 4.19485727566666, 
2.3737108016, 6.58823506033333, 6.58823506033333, 2.33729970666667, 
1.35043392, 2.33729970666667, 0.7918773089276, 2.64941819863333, 
2.64941819863333, 1.84968858666667, 6.58823506033333, 1.69423596966667, 
2.82831107136667, 3.22375391666666, 4.14114214399999, 0.816646300333333, 
4.14114214399999, 6.58823506033333, 0.7918773089276, 2.64941819863333, 
0.7918773089276, 4.14114214399999, 1.69423596966667, 3.22375391666666, 
6.58823506033333, 2.82831107136667, 6.58823506033333, 1.69423596966667, 
1.69423596966667, 0.7918773089276, 2.64941819863333, 2.33729970666667, 
2.82831107136667, 1.15469864333333, 4.14114214399999, 0.816646300333333, 
2.82831107136667, 2.64941819863333, 0.7918773089276, 6.58823506033333, 
1.69423596966667, 6.58823506033333, 3.66557223, 2.82831107136667, 
6.58823506033333, 0.7918773089276, 2.82831107136667, 3.22375391666666, 
4.14114214399999, 2.33729970666667), grid = c("Southeast grid", 
"Southeast grid", "Southwest grid", "California grid", "Southwest grid", 
"New England grid", "Mid-Atlantic grid", "Mid-Atlantic grid", 
"Florida grid", "Southeast grid", "Central Northwest grid", "Northwest grid", 
"Central Northeast grid", "Central East grid", "Central Southwest grid", 
"Central East grid", "Southeast grid", "New England grid", "Mid-Atlantic grid", 
"New England grid", "Central East grid", "Central Northwest grid", 
"Central Northeast grid", "Southeast grid", "Northwest grid", 
"Southeast grid", "Central Northwest grid", "Central Northwest grid", 
"New England grid", "Mid-Atlantic grid", "Southwest grid", "Northwest grid", 
"New York grid", "Central East grid", "Central Southwest grid", 
"Northwest grid", "Mid-Atlantic grid", "New England grid", "Southeast grid", 
"Central Northwest grid", "Southeast grid", "Texas grid", "Northwest grid", 
"Southeast grid", "New England grid", "Northwest grid", "Central Northeast grid", 
"Central East grid", "Southwest grid", "Southeast grid", "Southeast grid", 
"Southwest grid", "California grid", "Southwest grid", "New England grid", 
"Mid-Atlantic grid", "Mid-Atlantic grid", "Florida grid", "Southeast grid", 
"Central Northwest grid", "Northwest grid", "Central Northeast grid", 
"Central East grid", "Central Southwest grid", "Central East grid", 
"Southeast grid", "New England grid", "Mid-Atlantic grid", "New England grid", 
"Central East grid", "Central Northwest grid", "Central Northeast grid", 
"Southeast grid", "Northwest grid", "Southeast grid", "Central Northwest grid", 
"Central Northwest grid", "New England grid", "Mid-Atlantic grid", 
"Southwest grid", "Northwest grid", "New York grid", "Central East grid", 
"Central Southwest grid", "Northwest grid", "Mid-Atlantic grid", 
"New England grid", "Southeast grid", "Central Northwest grid", 
"Southeast grid", "Texas grid", "Northwest grid", "Southeast grid", 
"New England grid", "Northwest grid", "Central Northeast grid", 
"Central East grid", "Southwest grid", "Southeast grid", "Southeast grid", 
"Southwest grid", "California grid", "Southwest grid", "New England grid", 
"Mid-Atlantic grid", "Mid-Atlantic grid", "Florida grid", "Southeast grid", 
"Central Northwest grid", "Northwest grid", "Central Northeast grid", 
"Central East grid", "Central Southwest grid", "Central East grid", 
"Southeast grid", "New England grid", "Mid-Atlantic grid", "New England grid", 
"Central East grid", "Central Northwest grid", "Central Northeast grid", 
"Southeast grid", "Northwest grid", "Southeast grid", "Central Northwest grid", 
"Central Northwest grid", "New England grid", "Mid-Atlantic grid", 
"Southwest grid", "Northwest grid", "New York grid", "Central East grid", 
"Central Southwest grid", "Northwest grid", "Mid-Atlantic grid", 
"New England grid", "Southeast grid", "Central Northwest grid", 
"Southeast grid", "Texas grid", "Northwest grid", "Southeast grid", 
"New England grid", "Northwest grid", "Central Northeast grid", 
"Central East grid", "Southwest grid", "Southeast grid", "Southeast grid", 
"Southwest grid", "California grid", "Southwest grid", "New England grid", 
"Mid-Atlantic grid", "Mid-Atlantic grid", "Florida grid", "Southeast grid", 
"Central Northwest grid", "Northwest grid", "Central Northeast grid", 
"Central East grid", "Central Southwest grid", "Central East grid", 
"Southeast grid", "New England grid", "Mid-Atlantic grid", "New England grid", 
"Central East grid", "Central Northwest grid", "Central Northeast grid", 
"Southeast grid", "Northwest grid", "Southeast grid", "Central Northwest grid", 
"Central Northwest grid", "New England grid", "Mid-Atlantic grid", 
"Southwest grid", "Northwest grid", "New York grid", "Central East grid", 
"Central Southwest grid", "Northwest grid", "Mid-Atlantic grid", 
"New England grid", "Southeast grid", "Central Northwest grid", 
"Southeast grid", "Texas grid", "Northwest grid", "Southeast grid", 
"New England grid", "Northwest grid", "Central Northeast grid", 
"Central East grid", "Southwest grid"), emission = c("Low Emission", 
"Low Emission", "Low Emission", "Low Emission", "Low Emission", 
"Low Emission", "Low Emission", "Low Emission", "Low Emission", 
"Low Emission", "Low Emission", "Low Emission", "Low Emission", 
"Low Emission", "Low Emission", "Low Emission", "Low Emission", 
"Low Emission", "Low Emission", "Low Emission", "Low Emission", 
"Low Emission", "Low Emission", "Low Emission", "Low Emission", 
"Low Emission", "Low Emission", "Low Emission", "Low Emission", 
"Low Emission", "Low Emission", "Low Emission", "Low Emission", 
"Low Emission", "Low Emission", "Low Emission", "Low Emission", 
"Low Emission", "Low Emission", "Low Emission", "Low Emission", 
"Low Emission", "Low Emission", "Low Emission", "Low Emission", 
"Low Emission", "Low Emission", "Low Emission", "Low Emission", 
"Reference", "Reference", "Reference", "Reference", "Reference", 
"Reference", "Reference", "Reference", "Reference", "Reference", 
"Reference", "Reference", "Reference", "Reference", "Reference", 
"Reference", "Reference", "Reference", "Reference", "Reference", 
"Reference", "Reference", "Reference", "Reference", "Reference", 
"Reference", "Reference", "Reference", "Reference", "Reference", 
"Reference", "Reference", "Reference", "Reference", "Reference", 
"Reference", "Reference", "Reference", "Reference", "Reference", 
"Reference", "Reference", "Reference", "Reference", "Reference", 
"Reference", "Reference", "Reference", "Reference", "Low Emission", 
"Low Emission", "Low Emission", "Low Emission", "Low Emission", 
"Low Emission", "Low Emission", "Low Emission", "Low Emission", 
"Low Emission", "Low Emission", "Low Emission", "Low Emission", 
"Low Emission", "Low Emission", "Low Emission", "Low Emission", 
"Low Emission", "Low Emission", "Low Emission", "Low Emission", 
"Low Emission", "Low Emission", "Low Emission", "Low Emission", 
"Low Emission", "Low Emission", "Low Emission", "Low Emission", 
"Low Emission", "Low Emission", "Low Emission", "Low Emission", 
"Low Emission", "Low Emission", "Low Emission", "Low Emission", 
"Low Emission", "Low Emission", "Low Emission", "Low Emission", 
"Low Emission", "Low Emission", "Low Emission", "Low Emission", 
"Low Emission", "Low Emission", "Low Emission", "Low Emission", 
"Reference", "Reference", "Reference", "Reference", "Reference", 
"Reference", "Reference", "Reference", "Reference", "Reference", 
"Reference", "Reference", "Reference", "Reference", "Reference", 
"Reference", "Reference", "Reference", "Reference", "Reference", 
"Reference", "Reference", "Reference", "Reference", "Reference", 
"Reference", "Reference", "Reference", "Reference", "Reference", 
"Reference", "Reference", "Reference", "Reference", "Reference", 
"Reference", "Reference", "Reference", "Reference", "Reference", 
"Reference", "Reference", "Reference", "Reference", "Reference", 
"Reference", "Reference", "Reference", "Reference"), growth = c("Low Population/GDP", 
"Low Population/GDP", "Low Population/GDP", "Low Population/GDP", 
"Low Population/GDP", "Low Population/GDP", "Low Population/GDP", 
"Low Population/GDP", "Low Population/GDP", "Low Population/GDP", 
"Low Population/GDP", "Low Population/GDP", "Low Population/GDP", 
"Low Population/GDP", "Low Population/GDP", "Low Population/GDP", 
"Low Population/GDP", "Low Population/GDP", "Low Population/GDP", 
"Low Population/GDP", "Low Population/GDP", "Low Population/GDP", 
"Low Population/GDP", "Low Population/GDP", "Low Population/GDP", 
"Low Population/GDP", "Low Population/GDP", "Low Population/GDP", 
"Low Population/GDP", "Low Population/GDP", "Low Population/GDP", 
"Low Population/GDP", "Low Population/GDP", "Low Population/GDP", 
"Low Population/GDP", "Low Population/GDP", "Low Population/GDP", 
"Low Population/GDP", "Low Population/GDP", "Low Population/GDP", 
"Low Population/GDP", "Low Population/GDP", "Low Population/GDP", 
"Low Population/GDP", "Low Population/GDP", "Low Population/GDP", 
"Low Population/GDP", "Low Population/GDP", "Low Population/GDP", 
"Low Population/GDP", "Low Population/GDP", "Low Population/GDP", 
"Low Population/GDP", "Low Population/GDP", "Low Population/GDP", 
"Low Population/GDP", "Low Population/GDP", "Low Population/GDP", 
"Low Population/GDP", "Low Population/GDP", "Low Population/GDP", 
"Low Population/GDP", "Low Population/GDP", "Low Population/GDP", 
"Low Population/GDP", "Low Population/GDP", "Low Population/GDP", 
"Low Population/GDP", "Low Population/GDP", "Low Population/GDP", 
"Low Population/GDP", "Low Population/GDP", "Low Population/GDP", 
"Low Population/GDP", "Low Population/GDP", "Low Population/GDP", 
"Low Population/GDP", "Low Population/GDP", "Low Population/GDP", 
"Low Population/GDP", "Low Population/GDP", "Low Population/GDP", 
"Low Population/GDP", "Low Population/GDP", "Low Population/GDP", 
"Low Population/GDP", "Low Population/GDP", "Low Population/GDP", 
"Low Population/GDP", "Low Population/GDP", "Low Population/GDP", 
"Low Population/GDP", "Low Population/GDP", "Low Population/GDP", 
"Low Population/GDP", "Low Population/GDP", "Low Population/GDP", 
"Low Population/GDP", "High Population/GDP", "High Population/GDP", 
"High Population/GDP", "High Population/GDP", "High Population/GDP", 
"High Population/GDP", "High Population/GDP", "High Population/GDP", 
"High Population/GDP", "High Population/GDP", "High Population/GDP", 
"High Population/GDP", "High Population/GDP", "High Population/GDP", 
"High Population/GDP", "High Population/GDP", "High Population/GDP", 
"High Population/GDP", "High Population/GDP", "High Population/GDP", 
"High Population/GDP", "High Population/GDP", "High Population/GDP", 
"High Population/GDP", "High Population/GDP", "High Population/GDP", 
"High Population/GDP", "High Population/GDP", "High Population/GDP", 
"High Population/GDP", "High Population/GDP", "High Population/GDP", 
"High Population/GDP", "High Population/GDP", "High Population/GDP", 
"High Population/GDP", "High Population/GDP", "High Population/GDP", 
"High Population/GDP", "High Population/GDP", "High Population/GDP", 
"High Population/GDP", "High Population/GDP", "High Population/GDP", 
"High Population/GDP", "High Population/GDP", "High Population/GDP", 
"High Population/GDP", "High Population/GDP", "High Population/GDP", 
"High Population/GDP", "High Population/GDP", "High Population/GDP", 
"High Population/GDP", "High Population/GDP", "High Population/GDP", 
"High Population/GDP", "High Population/GDP", "High Population/GDP", 
"High Population/GDP", "High Population/GDP", "High Population/GDP", 
"High Population/GDP", "High Population/GDP", "High Population/GDP", 
"High Population/GDP", "High Population/GDP", "High Population/GDP", 
"High Population/GDP", "High Population/GDP", "High Population/GDP", 
"High Population/GDP", "High Population/GDP", "High Population/GDP", 
"High Population/GDP", "High Population/GDP", "High Population/GDP", 
"High Population/GDP", "High Population/GDP", "High Population/GDP", 
"High Population/GDP", "High Population/GDP", "High Population/GDP", 
"High Population/GDP", "High Population/GDP", "High Population/GDP", 
"High Population/GDP", "High Population/GDP", "High Population/GDP", 
"High Population/GDP", "High Population/GDP", "High Population/GDP", 
"High Population/GDP", "High Population/GDP", "High Population/GDP", 
"High Population/GDP", "High Population/GDP", "High Population/GDP"
)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA, 
-196L))

您将需要使用 shapefiles/简单特征 [sf] 对象而不仅仅是数据框。

usmap 包是一个高级包,旨在方便地生成标准美国地图。它不附带 shapefile,但包含实际数据帧中的多边形数据(由包提供)美国地图数据。该包不支持自定义状态合并。

合并数据框中的多边形并非不可能,但并不容易。它还将重新发明轮子,因为顺丰包就是为了这样的事情而建造的。但它仅适用于 shapefile / sf 对象。

好消息,美国在 R 世界中并不是一个不受欢迎的国家,并且还有其他包含美国地图数据的 R 包,例如USAboundaries,带有 shapefile。

sf包允许你合并(这里这个过程称为unionise) 轻松绘制多边形,例如并进行简单的总结。 (见下文)。

然后你可以使用ggplot2自己的geom_sf对于联合多边形和geom_sf_text or geom_sf_label对于标签。

代码中的进一步注释。

library(tidyverse)
## use for example this for US shapefile maps
library(USAboundaries)
## you will need the sf package for some stuff
library(sf)

# my_data <- ... from your question above

states <- us_states()
states <- states[!states$name %in% c("Alaska", "Hawaii"),]
##remove arrange
states_data <- left_join(states, my_data, by = c("state_abbr" = "region" )) %>%
## there is an NA value that needs removal
drop_na(grid)

## this is to unionise the polygons
custom_grids <- 
  states_data %>%
## group by all the variables that occur in the facets
  group_by(grid, emission, growth) %>%
  summarise(value = mean(value))

## you can now plot the unionised polygon sf object with geom_sf and geom_sf_text for labels
ggplot(custom_grids) +
  geom_sf(aes(fill = value)) +
  geom_sf_text(aes(label = grid), check_overlap = T)+
  scale_fill_viridis_c() +
  facet_grid(emission~growth) 
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何将特定状态按组与R中的ggplot2中的一个标签合并在一起? 的相关文章

  • 使用 R Markdown 文档作为函数源

    我正在研究 R Markdown 来记录我经常使用的功能 我会将它们放入 R Markdown 文件中以记录它们 然后如果我几个月后回来查看它 就能够阅读我在函数背后的想法 我的问题是 如果我开始一个新的 R 项目 是否可以获取 r mar
  • 来自大型数据帧的共现

    我有一个数据框 其中包含有关每个用户访问过哪些城市的信息 df visited lt data frame user c john john claire claire doe doe city c Antananarivo Barcelo
  • 构造奎因(自我复制功能)

    有没有人构建过 quine 生成自己源文本的副本作为其完整输出的程序 http www nyx net gthompso quine htm http www nyx net gthompso quine htm 在 R 中 quine 标
  • R 3.5 - read.csv 无法读取 UTF-16 csv 文件

    我的代码如下 read csv http asic gov au Reports YTD 2018 RR20180420 001 SSDailyYTD csv skip 1 fileEncoding UTF 16 sep t header
  • 如何对范围内的行进行分组并考虑第三列?

    我有一个遗传数据集 我想对基因组中物理上靠近的遗传变异 行进行分组 我想对每条染色体基因组中某些点范围内的基因进行分组 chrom 我的 点 数据集包含变体 行需要在一定范围内的位置 如下所示 chrom low high 1 500 17
  • 使用矢量相应地更改传单线条的颜色

    无论如何 是否可以根据某些变量的值更改传单线条的颜色 我用谷歌搜索 发现了这个link http hgoebl github io Leaflet MultiOptionsPolyline demo 然而 我想知道是否有一种简单的方法可以在
  • Matlab 中是否有相当于 R 的 dput() 的函数?

    Matlab 中是否有相当于 R 的 dput 的函数 dput 将 R 对象的 ASCII 文本表示形式写入文件或连接 UPDATE 1 添加了递归和对单元格的支持 UPDATE 2 添加了对结构的支持 UPDATE 3 增加了对逻辑 整
  • R中data.frame(列表)的列平均值

    Data https i stack imgur com ZYsmv jpg 请 我需要计算此 data frame 中维吉尼亚币 Sepal Length 列的平均值 Sepal Length Sepal Width Petal Leng
  • 从 leafletProxy() 返回渲染的传单地图

    是否可以在渲染后在 Shiny 中检索传单地图 下面是一个代码示例 展示了如何生成地图leaflet 与返回的不同leafletProxy 即使它们在渲染时看起来完全相同 是否有一个功能可能不同于leafletProxy 获取实际的 htm
  • NumericVector 和 vector 之间有性能差异吗?

    假设有人使用NumericVector和其他用途vector
  • 如果落在 R 中另一个数据集中的两个变量定义的范围内,则从一个数据集中获取变量值

    我有一个关于 R 中日期操作的问题 我已经查了好几天了 但在网上找不到任何帮助 我有一个数据集 其中有 id 和两个日期 另一个数据集具有相同的 id 变量 日期和价格 例如 x data frame id c A B C C date1
  • 在 R 中计算大矩阵的零空间

    我找不到任何函数或包来计算 a 的零空间或 QR 分解 bigmatrix from library bigmemory 在 R 中 例如 library bigmemory a lt big matrix 1000000 1000 typ
  • dplyr::group_by_ 带有多个变量名的字符串输入

    我正在编写一个函数 要求用户在函数调用中定义一个或多个分组变量 然后使用 dplyr 对数据进行分组 如果只有一个分组变量 它会按预期工作 但我还没有弄清楚如何使用多个分组变量来做到这一点 Example x lt c cyl y lt c
  • R xts 对象中从每日时间序列到每周时间序列

    我正在使用 Zoo 和 xts 包来分析财务数据 ts 包不太合适 因为金融系列有周末 没有可用数据 我读到了 xts 包中可用的 apply 函数 apply daily x FUN apply weekly x FUN apply mo
  • 使用栅格包下载 SRTM 数据?

    我正在尝试使用 获取 SRTM 数据 raster R 中的包 但一旦我选择SRTM在 getData 命令中 我会收到以下错误 library raster srtm lt getData SRTM lon 16 lat 48 tryin
  • 如何自动替换多个文件的文本内容中的字符?

    我有一个文件夹 myfolder包含许多乳胶表 我需要替换其中每个字符 即替换任何minus sign by an en dash 只是为了确定 我们正在替换连字符INSIDE该文件夹中的所有 tex 文件 我不关心 tex 文件名 手动执
  • R ggplot:加权 CDF

    我想使用绘制加权 CDFggplot 一些旧的非 SO 讨论 例如this https stat ethz ch pipermail r help 2012 October 337288 html从 2012 年起 建议这是不可能的 但我想
  • 时间序列,将月度数据改为季度

    现在我有一些每月数据 例如 1 1 90 620 2 1 90 591 3 1 90 574 4 1 90 542 5 1 90 534 6 1 90 545 etc 如果我使用 ts 函数 很容易将数据转换为时间序列结构 例如 Jan F
  • 从拟合的 lm 或 glm [R] 获取每个因子水平(以及交互作用)的数据数量

    我在 R 中有一个逻辑回归模型 其中所有预测变量都是分类变量而不是连续变量 除了响应变量 它显然也是分类 二元变量 打电话时summary model name 有没有办法在每个因子水平中包含一个表示观测值数量的列 我在 R 中有一个逻辑回
  • R - 加速近似日期匹配。 idata.frame?

    我正在努力有效地执行两个数据帧之间的 关闭 日期匹配 这个问题探索了一个解决方案 使用idata frame来自plyr包 但我也对其他建议的解决方案感到非常满意 这是两个数据框的非常简单的版本 sampleticker lt data f

随机推荐

  • Java 维基文本解析器 [关闭]

    Closed 这个问题正在寻求书籍 工具 软件库等的推荐 不满足堆栈溢出指南 help closed questions 目前不接受答案 对于一个具有易于使用且可配置的 API 的漂亮解析器有什么想法吗 我希望向其提供数据 例如 选择我想要
  • iPad 屏幕不支持自动布局

    I have created view using autolayout it works fine in all iPhone devices but it left some blank space at left right top
  • xcode 6.1 iOS 8.1 NSLocale displayNameForKey NSLocaleIdentifier 返回 nil

    NSString countryNameByCode NSString countryCode NSString identifier NSLocale localeIdentifierFromComponents NSLocaleCoun
  • 从 1 个单词的字符串中提取数字

    在我试图制作的这个程序中 我有一个表达式 例如 I 23mm 或 H 4V 并且我试图从中提取 23 或 4 以便我可以把它变成一个整数 我一直遇到的问题是 由于我试图取出数字的表达式是 1 个单词 所以我不能使用 split 或任何东西
  • C++:Linux 中的计时(使用 Clock())不同步(由于 OpenMP?)

    在程序的顶部和结尾 我使用clock 来计算程序需要多长时间才能完成 不幸的是 它似乎只花费了报告时间的一半 我用 time 命令仔细检查了这一点 我的程序报告 45 86秒完成 时间命令报告 真实0米22 837秒 用户 0m45 735
  • 在 Python TCP 流中使用分隔符

    我正在开发一个使用 TCP 协议从天线收集 ADS B 消息的程序 由于我是Python新手 我使用以下脚本来建立连接 问题是我同时收到多条消息 因为 TCP 是面向流的 例如 我想使用 n 分隔符分隔每条消息 每条消息开头有 结尾有 长度
  • 获取 Woocommerce 中当天的订单总购买金额

    对于 Woocommerce 我在下面编写了代码 试图获取今天的订单总购买金额 function order total woo fahad Get orders from people named John that were paid
  • 如何更新xslt中的变量值?

    我已在 xsl 文件中声明了一个变量 现在我想用新值更新旧值 例如
  • 使用 WiX 打包包含许多文件的安装程序

    我有一个包含数百个文件的 WiX 3 项目 我似乎不知道如何使用通配符将它们全部包含在内 我已经尝试过这个 heat exe dir Build gg ke template fragment out Files wxs 这会生成一个片段
  • 当视图被推送时,UISearchController 不会被关闭

    我知道这是一篇很长的文章 但这只是我保证的一个问题 设置 我在 UISearchController 中遇到了一些非常奇怪的行为 让我描述一下层次结构 然后我将逐步解释视频中发生的情况 您看到的第一个视图是常规 ViewController
  • 这个 typedef 是什么意思?

    我是 C 新手 这个 typedef 对我来说看起来有点奇怪 有人可以解释它的作用吗 typedef void alpm cb log alpm loglevel t const char va list 它位于头文件中 您可以使用 cde
  • 当 PythonOperator 出现错误“Negsignal.SIGKILL”时,Airflow DAG 失败

    我在 Cloud Composer v1 16 16 上运行 Airflowv1 10 15 我的 DAG 看起来像这样 from datetime import datetime timedelta imports from airflo
  • 在多线程代码中出于性能原因应避免什么?

    我目前正在审查 重构一个多线程应用程序 该应用程序应该是多线程的 以便能够使用所有可用的内核并理论上提供更好 卓越的性能 卓越是更好的商业术语 P 编写多线程应用程序时应该注意哪些事项 我的意思是那些会极大地影响性能的事情 甚至可能达到这样
  • 更改用于 TF 命令行的登录帐户

    当使用TFS 2012的命令行版本时 我们调用 TF exe get Path To Team Project Some Folder recursive 通过命令行提示符的调用 我的命令成功了 我没有为此通话输入任何用户名 密码 我想更改
  • 我正在运行哪个版本的 PostgreSQL?

    我在企业环境中 运行Debian Linux 并且没有自己安装它 我使用 Navicat 或 phpPgAdmin 访问数据库 如果有帮助的话 我也没有对运行数据库的服务器的外壳访问权限 从 PostgreSQL 运行此查询 SELECT
  • RxSwift:BehaviorRelay 代替变量使用

    我是 RxSwift 的新手 正在阅读有关主题的内容 我尝试过Variable主题 这又在控制台中发出警告 DEPRECATED Variable is planned for future deprecation Please consi
  • 有没有更简洁的方法来注册 Qt 自定义事件?

    我需要为 Qt 应用程序创建几个自定义事件类 现在 看起来我需要为每个事件类实现以下事件类型注册代码 class MyEvent public QEvent public MyEvent QEvent registeredType stat
  • AUTH_LOGIN 获取完成后如何调用 AUTH_CHECK?

    我正在调用 HTTP API 以使用返回承诺的 axios 登录 AUTH LOGIN 在 API 调用完成之前 AUTH CHECK 被调用并失败 是否可以仅在 http 调用完成后触发 AUTH CHECK 请在下面找到我的 authp
  • Android:如何使用相同的相机意图拍摄多张照片

    我制作了一个 Android 应用程序 可以一张一张地拍摄照片 存储它们 向用户提供预览等等 所有这些任务都是通过类型意图来完成的ACTION IMAGE CAPTURE 所以 每次用户想要拍照时 他应该点击启动意图的 拍照按钮 等待几秒钟
  • 如何将特定状态按组与R中的ggplot2中的一个标签合并在一起?

    我想绘制美国的电网地图 所以我需要将特定的州合并在一起 我想为这些状态绘制边界 但它不起作用 每组也只有一个标签 这是我的数据 https iastate box com s 12xru62lvmbbkrohsn7b4wwexq11umn7