return 将函数的绘图和值放在一起
return plot and values from a function together
我有这样的功能:
fun <- function(dataset){
require(ggplot2)
g <- ggplot(dataset, aes(x = x, y = y)) + geom_smooth(method = "lm") + geom_point()
l<-lm(y~x)
return (list(l, g))
}
我想return绘图和值,但它没有return绘图,我遇到这个错误:
Error in .Call.graphics(C_palette2, .Call(C_palette2, NULL)) :
invalid graphics state
我能做什么?
以下作品,剧情一览。但是,R 警告说这不是这样做的方法。
fun <- function(dataset){
require(ggplot2)
p <- ggplot(dataset, aes(x = x, y = y)) +
geom_smooth(method = "lm") + geom_point()
l <- lm(y~x, data=dataset)
return (list(l, p))
}
dataset <- data.frame(x= 1:10, y=1:10)
out <- fun(dataset)
编辑:我已经查看了警告,您似乎可以忽略它。见 link https://stat.ethz.ch/pipermail/r-devel/2016-December/073554.html
我有这样的功能:
fun <- function(dataset){
require(ggplot2)
g <- ggplot(dataset, aes(x = x, y = y)) + geom_smooth(method = "lm") + geom_point()
l<-lm(y~x)
return (list(l, g))
}
我想return绘图和值,但它没有return绘图,我遇到这个错误:
Error in .Call.graphics(C_palette2, .Call(C_palette2, NULL)) :
invalid graphics state
我能做什么?
以下作品,剧情一览。但是,R 警告说这不是这样做的方法。
fun <- function(dataset){
require(ggplot2)
p <- ggplot(dataset, aes(x = x, y = y)) +
geom_smooth(method = "lm") + geom_point()
l <- lm(y~x, data=dataset)
return (list(l, p))
}
dataset <- data.frame(x= 1:10, y=1:10)
out <- fun(dataset)
编辑:我已经查看了警告,您似乎可以忽略它。见 link https://stat.ethz.ch/pipermail/r-devel/2016-December/073554.html