I have a function that reads in multiple fields from a large csv file then does some calculations and plots the points according to the specified fields. I want to label the axes of the output plot with the field name entered in the function parameters. For example, you would choose for the sales
field to be pulled from the csv and plotted on the y-axis and labeled sales
.
QAD<-function(x.axis,y.axis,pt.size,quad.div.x,quad.div.y){
dfull<-read.csv("QADR.csv",header=TRUE)
...
plot(xd, yd, cex=size, xlab=deparse(substitute(x.axis))
,ylab=deparse(substitute(y.axis)))
...
}
deparse(substitute(x.axis))
is the closest solution I have found (How to convert variable (object) name into String) but that labels it y.axis
instead of the field name. Is there any way I can store the input y.axis
as a string?