Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
函数内部的R赋值 库(tidyverse) xy_R_Function_Ggplot2_Variable Assignment - Fatal编程技术网

函数内部的R赋值 库(tidyverse) xy

函数内部的R赋值 库(tidyverse) xy,r,function,ggplot2,variable-assignment,R,Function,Ggplot2,Variable Assignment,您需要在数据框的上下文中计算xvar: plotfunc <- function(data, x, y){ rng <- range(substitute(x), na.rm = TRUE) rescale <- (substitute(x) - rng[1]) / (rng[2] - rng[1]) print( ggplot(data, aes_(x = substitute(x), y = substitute(y))) + geom_l

您需要在
数据框的上下文中计算
xvar

plotfunc <- function(data, x, y){
  rng <- range(substitute(x), na.rm = TRUE)
  rescale <- (substitute(x) - rng[1]) / (rng[2] - rng[1])
  print(
    ggplot(data, aes_(x = substitute(x), y = substitute(y))) + 
      geom_line()
  )
}
plotfunc(xy, xvar, yvar)

plotfunc您需要在
data.frame的上下文中计算
xvar

plotfunc <- function(data, x, y){
  rng <- range(substitute(x), na.rm = TRUE)
  rescale <- (substitute(x) - rng[1]) / (rng[2] - rng[1])
  print(
    ggplot(data, aes_(x = substitute(x), y = substitute(y))) + 
      geom_line()
  )
}
plotfunc(xy, xvar, yvar)

plotfunc这里是另一个使用更多tidyverse编程风格的选项:

plotfunc <- function(data, x, y){
  rng <- range(eval(substitute(x),envir = data), na.rm = TRUE)
  rescale <- (eval(substitute(x),envir = data) - rng[1]) / (rng[2] - rng[1])
  print(
    ggplot(data, aes_(x = substitute(x), y = substitute(y))) + 
      geom_line()
  )
}
plotfunc(xy, xvar, yvar)
库(tidyverse)

xy这里是另一个使用tidyverse编程风格的选项:

plotfunc <- function(data, x, y){
  rng <- range(eval(substitute(x),envir = data), na.rm = TRUE)
  rescale <- (eval(substitute(x),envir = data) - rng[1]) / (rng[2] - rng[1])
  print(
    ggplot(data, aes_(x = substitute(x), y = substitute(y))) + 
      geom_line()
  )
}
plotfunc(xy, xvar, yvar)
库(tidyverse)

xy对于使用
tidyverse
编程,您可能会对此资源感兴趣:对于使用
tidyverse
编程,您可能会对此资源感兴趣:我建议选择/拉动/范围(仅调用一次),而不是摘要我建议选择/拉动/范围(仅调用一次),而不是摘要