简体   繁体   English

match.arg(regions) 中的错误:“arg”必须为 NULL 或字符向量

[英]Error in match.arg(regions) : 'arg' must be NULL or a character vector

I want to make a map on r for and show the price-elasticity by the intensity of the color.我想在 r 上制作一张地图,并通过颜色的强度显示价格弹性。 This is the data that I have made using linear regression:这是我使用线性回归制作的数据:

在此处输入图片说明

    IN  log_PRICE   -1.1059770  0.05943414  -18.60845   7.186435e-72
    KY  log_PRICE   -1.0459502  0.03410250  -30.67078   2.739798e-196
    OH  log_PRICE   -0.9076732  0.01259117  -72.08806   0.000000e+00
    TX  log_PRICE   -0.2252409  0.01053847  -21.37321   4.117490e-101
    IN  log_PRICE   -1.1059770  0.05943414  -18.60845   7.186435e-72
    KY  log_PRICE   -1.0459502  0.03410250  -30.67078   2.739798e-196
    OH  log_PRICE   -0.9076732  0.01259117  -72.08806   0.000000e+00
    TX  log_PRICE   -0.2252409  0.01053847  -21.37321   4.117490e-101

library(usmap)
library(ggplot2)
library(tmpa)
library(sf)
library(leaflet)

plot_usmap(regions="state", data = CC1, values = "estimate", 
    include = c("IN", "KY", "OH", "TX"), color = "orange") + 
  scale_fill_continuous(low = "white", high = "orange", 
     name = "Price elasticity", label = scales::comma) + 
  labs(title = "Price elasticity for Cold Cereal", 
       subtitle = "States include: IN, KY, OH, TX") +
  theme(legend.position = "right") 

#That is the code I wrote but I keep getting this error
Error in match.arg(regions) : 'arg' must be NULL or a character vector

I am not sure what caused the error.我不确定是什么导致了错误。 It seems that a non-character vector was used although the function requires a character vector, maybe.尽管该函数可能需要字符向量,但似乎使用了非字符向量。 You want to compare between your code and mine.您想在您的代码和我的代码之间进行比较。 Perhaps, you want to check data as well.也许,您还想检查数据。 The following is working for me.以下是为我工作。

plot_usmap(data = mydata, values = "estimate",
           regions = "state", include = c("IN", "KY", "OH", "TX")) +
scale_fill_continuous(low = "white", high = "orange", 
                      name = "Price elasticity", label = scales::comma) + 
labs(title = "Price elasticity for Cold Cereal", 
     subtitle = "States include: IN, KY, OH, TX") +
theme(legend.position = "right")

在此处输入图片说明

For fun, the following is my own version with the albersusa package.为了好玩,以下是我自己的带有 albersusa 包的版本。

library(tydyverse)
library(sf)
library(albersusa)
library(viridis)

mysf <- left_join(usa_sf("laea"), mydata, by = c("iso_3166_2" = "state")) 

ggplot() +
geom_sf(data = mysf, aes(fill = estimate)) +
scale_fill_viridis(discrete = FALSE, option = "plasma")

在此处输入图片说明

DATA数据

mydata <- structure(list(state = c("IN", "KY", "OH", "TX"), log = c("log_PRICE", 
"log_PRICE", "log_PRICE", "log_PRICE"), estimate = c(-1.105977, 
-1.0459502, -0.9076732, -0.2252409), se = c(0.05943414, 0.0341025, 
0.01259117, 0.01053847), statistic = c(-18.60845, -30.67078, 
-72.08806, -21.37321), pvalue = c(7.186435e-72, 2.739798e-196, 
0, 4.11749e-101)), class = "data.frame", row.names = c(NA, -4L
))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 警告:match.arg中的错误:&#39;arg&#39;必须为NULL或字符向量 - Warning: Error in match.arg: 'arg' must be NULL or a character vector 运行应用程序时出现闪亮错误:match.arg(position) 中的错误:&#39;arg&#39; 必须为 NULL 或字符向量 - Shiny Error when running App: Error in match.arg(position) : 'arg' must be NULL or a character vector match.arg(opt_crit)中的错误:“ arg”必须为NULL或字符向量 - Error in match.arg(opt_crit) : 'arg' must be NULL or a character vector Shiny 应用程序中的“match.arg(position) 错误:‘arg’必须为 NULL 或字符向量” - "Error in match.arg(position) : 'arg' must be NULL or a character vector" in Shiny app match.arg(p.adjust.method)中的错误:“ arg”必须为NULL或字符向量 - Error in match.arg(p.adjust.method) : 'arg' must be NULL or a character vector match.arg(position) 中的闪亮错误:“arg”必须为 NULL 或字符向量 - shiny Error in match.arg(position) : 'arg' must be NULL or a character vector 尝试运行以下代码中的插补函数时,“match.arg(what) 中的错误:&#39;arg&#39; 必须为 NULL 或字符向量” - "Error in match.arg(what) : 'arg' must be NULL or a character vector" when trying to run the impute function in the below code match.arg(mvnTest)中的错误:“ arg”的长度必须为1 - Error in match.arg(mvnTest) : 'arg' must be of length 1 &#39;arg&#39;必须为NULL或字符向量 - 'arg' must be NULL or a character vector 对多个 arguments 使用 match.arg 时出错 - Error in using match.arg for multiple arguments
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM