使用;单位「;作为facet“u wrap plot with expand“u limit returns”中的变量;无法强制类型';关闭';到类型为'的向量;字符'&引用;

使用;单位「;作为facet“u wrap plot with expand“u limit returns”中的变量;无法强制类型';关闭';到类型为'的向量;字符'&引用;,r,ggplot2,R,Ggplot2,当我使用unit作为镶嵌面变量时,ggplot返回一个错误 library(ggplot2) # Create and additional unit variable cars$unit <- c(rep("mph",25),rep("smthingelse",25)) # Error ggplot(cars, aes(x=speed, y=dist)) + geom_point() + expand_limits(y=0) + facet_wrap(~uni

当我使用
unit
作为镶嵌面变量时,ggplot返回一个错误

library(ggplot2)
# Create and additional unit variable
cars$unit <- c(rep("mph",25),rep("smthingelse",25))
# Error
ggplot(cars, aes(x=speed, y=dist)) + 
    geom_point() + 
    expand_limits(y=0) +
    facet_wrap(~unit)
# Error in as.character(what) : 
#   cannot coerce type 'closure' to vector of type 'character'

它与共享相同的错误消息,但我认为这与此无关。我试过了,但没有使用
facet\u wrap(~substitute(unit))

这是由于ggplot2的旧版本造成的

install.packages("ggplot2")

修复了我的问题。

这是由于ggplot2的旧版本造成的

install.packages("ggplot2")

修复了我的问题。

您的示例对我来说运行正常,没有错误<代码>单元是网格包中相当重要的功能,ggplot2就是基于此构建的。您可能有一个较旧版本的ggplot2,其中有一个现已修复的错误,该错误在某些情况下会导致名称冲突。我不知道该错误,它同时适用于unit和unit2。感谢我将ggplot2更新为更新的版本
install.packages(“ggplot2”)
修复了它。出于好奇,我检查了
网格
包,惊讶地发现了这一点。说明
grid
已成为一个基本包。您的示例为我运行,没有错误<代码>单元是网格包中相当重要的功能,ggplot2就是基于此构建的。您可能有一个较旧版本的ggplot2,其中有一个现已修复的错误,该错误在某些情况下会导致名称冲突。我不知道该错误,它同时适用于unit和unit2。感谢我将ggplot2更新为更新的版本
install.packages(“ggplot2”)
修复了它。出于好奇,我检查了
网格
包,惊讶地发现了这一点。说明
grid
已成为基本包。