我正在尝试创建一个函数来绘制变量的散点图,如下所示:
plotting = function(x,y){
plot(x, y,
main= "PM10 and Electricity use",
ylab= "",
xlab= "",
col= "blue", pch = 19, cex = 1, lty = "solid", lwd = 2)
}
y = PM10
x = Total_E*population
plotting(x,y)
(注:PM10、Total_E、population均为数字向量)
是否可以将xlab
, ylab
改为变量的名称,将ylab
改为"PM10",将xlab
改为"Total_E*population"甚至"Total_E times population"?
您正在寻找非标准评估。这是通过substitute
和deparse
实现的. ...
plotting <- function(x, y) {
plot(x, y, main = "PM10 and Electricity use",
ylab = deparse(substitute(y)),
xlab = deparse(substitute(x))
)
}