箱线图错误,缺少参数 "x",没有默认值
Error in boxplot, argument "x" is missing, with no default
我正在尝试在 R markdown 中使用两个变量(在 .xlsx 文件中命名为 "suicides/100k pop" 和 "sex",其中 "sex" 是标称选项 male/female) 但它没有产生情节。
suicidedata = as.data.frame(readxl::read_xlsx(
path = "(...)\suicidedata.xlsx",
))
boxplot(
formula = "suicides/100k pop" ~ "sex",
)
错误:
Error in boxplot.default(formula ="suicides/100k pop" ~ "sex", : argument "x" is missing, with no default calls: ... withVisible -> eval -> eval -> boxplot -> boxplot.default Execution
如何让它打印箱线图?
我们可以把双引号改成backquote
,指定data
boxplot(
formula = `suicides/100k pop` ~ sex, data = suicidedata)
一个可重现的例子
data(iris)
names(iris)[1] <- 'Sepal.Length/100k pop'
双引号在这里不起作用
boxplot("Sepal.Length/100k pop" ~ Species, data = iris)
Error in terms.formula(formula, data = data) : invalid term in
model formula
反引号有效
boxplot(`Sepal.Length/100k pop` ~ Species, data = iris)
我正在尝试在 R markdown 中使用两个变量(在 .xlsx 文件中命名为 "suicides/100k pop" 和 "sex",其中 "sex" 是标称选项 male/female) 但它没有产生情节。
suicidedata = as.data.frame(readxl::read_xlsx(
path = "(...)\suicidedata.xlsx",
))
boxplot(
formula = "suicides/100k pop" ~ "sex",
)
错误:
Error in boxplot.default(formula ="suicides/100k pop" ~ "sex", : argument "x" is missing, with no default calls: ... withVisible -> eval -> eval -> boxplot -> boxplot.default Execution
如何让它打印箱线图?
我们可以把双引号改成backquote
,指定data
boxplot(
formula = `suicides/100k pop` ~ sex, data = suicidedata)
一个可重现的例子
data(iris)
names(iris)[1] <- 'Sepal.Length/100k pop'
双引号在这里不起作用
boxplot("Sepal.Length/100k pop" ~ Species, data = iris)
Error in terms.formula(formula, data = data) : invalid term in model formula
反引号有效
boxplot(`Sepal.Length/100k pop` ~ Species, data = iris)