【发布时间】:2016-01-16 12:43:18
【问题描述】:
在对数据框执行操作后生成ggplot() 图时遇到了意外问题。我提供了一个说明性示例:
func <- function(){
library(ggplot2)
df <- read.table(....)
# perform operation on df to retrieve column of interest index/number
column.index <- regexpr(...)
# now need to find variable name for this column
var.name <- names(df)[column.index]
# also need to mutate data in this column
df[,column.index] <- df[,column.index] * 10
# generate plot
plot <- ggplot(data, aes(x=var.name))+geom_bar()
print(plot)
}
这里 ggplot 会抛出一个错误,因为 var.name 被引用,例如,“mpg”。
知道如何解决这个问题吗?
编辑:来自this question 的测试解决方案无济于事。
【问题讨论】:
-
@David:我在 NSE 中测试了
quote,所以我添加了标签以提示问题的性质。 -
明白了。快速打字和思考,我想我说的:-)
标签: r ggplot2 dataframe quotes quoting