猿问

【R】ggplot 绘图报错「object 'viewsCount' not found」

histogram_plot <- function(varnames,binwidth,dataset){
  graph <- ggplot(aes(x = varnames),data = dataset)+
  geom_histogram(binwidth = binwidth)  return(graph)
}

histgram_plot(viewsCount,50,timeline)+
  xlim(c(0,8000))

代码如上,新建函数 histogram_plot ,调用此函数时报错。已检查 timeline 数据框中存在变量 viewsCount。

如果传入的是 timeline$viewsCount 则可以正常绘制图形。


守着一只汪
浏览 612回答 2
2回答

回首忆惘然

ggplot(aes(x = varnames),data = dataset)修改为ggplot(aes_string(x = varnames),data = dataset)

倚天杖

ref:What is the difference between aes and aes_string (ggplot2) in R - Stack Overflow
随时随地看视频慕课网APP

相关分类

Java
我要回答