如何在R中自定义plot()中的xlab名称?
我试图创建一个函数来绘制变量的散点图,如下所示:如何在R中自定义plot()中的xlab名称?,r,plot,R,Plot,我试图创建一个函数来绘制变量的散点图,如下所示: 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 plott
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、总量、人口均为数字向量。)
是否可以将
xlab
,ylab
更改为变量名称,例如ylab
更改为“PM10”,将xlab
更改为“总体”甚至“总体乘以总体”?您正在寻找非标准评估。这是通过substitute
和deparse
实现的
plotting <- function(x, y) {
plot(x, y, main = "PM10 and Electricity use",
ylab = deparse(substitute(y)),
xlab = deparse(substitute(x))
)
}
plotting编辑为plot函数添加缺少的参数。@如果有助于您奖励拼写错误的分数,您应该接受答案:)