Reputation: 197
code as below:
Raw=mtcars
cn=colnames(Raw)
sapply(1:7,function(i)ggplot(data=Raw,aes(x=Raw[,i],y=Raw[,i+1])+
geom_line()+geom_point(size=4,shape=20)+
labs(x='totality_accuray',y=cn[i]))
)
can help out what's issue to get this error reminder:Error in aes(x = Raw[, i], y = Raw[, i + 1]) + geom_line() : non-numeric argument to binary operator
Upvotes: 0
Views: 51
Reputation: 7153
Custom plotting function that take two named variables:
plotFn <- function(x,y, df){
ggplot(df,aes_string(x,y)) +
geom_line() +
geom_point(size=4,shape=20)
}
plotFn("disp", "cyl", mtcars)
Grabbing a list of variables for x and y axis:
Raw <- mtcars
cn <- colnames(Raw)
arg <- lapply(1:(ncol(Raw)-1), function(x) list(x = cn[x],
y = cn[x+1]))
Plotting 10 plots:
lapply(arg, function(i) plotFn(i[["x"]], i[["y"]], Raw))
Upvotes: 1