2015-08-31 27 views
0

我试图创建一个函数来绘制的变量散点图,类似如下:如何在R中的plot()中自定义xlab名称?

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,人口是数字的所有向量)

那是可能的将xlab,ylab改为变量的名称,比如说ylab到“PM10”,xlab改为“Total_E * population”,甚至是“Total_E times population”?

回答

0

您正在寻找非标准评估。这是通过substitutedeparse完成的。 ...

plotting <- function(x, y) { 
    plot(x, y, main = "PM10 and Electricity use", 
    ylab = deparse(substitute(y)), 
    xlab = deparse(substitute(x)) 
) 
} 
+0

太好了,非常感谢! – Chumoon

+0

编辑为绘图函数添加缺少的元素。 – misspelled

+0

@Chumoon你应该接受答案,如果它帮助你奖励拼错的应得分:) –

相关问题