I have written a function to create ggplot:
getLRplot <- function(grid_x, grid_y, price){
if(price == "reference"){
fill = "dodgerblue4"
}else if(price == "experience"){
fill = "grey46"
}else{
fill = "black"
}
paste("netLR", price, sep= "")
ggplot(BTplan, aes_string(x="noins1", y= paste("netLR", price, sep= ""))) +
geom_point(color = "dodgerblue4") +
facet_grid(as.formula(paste(grid_y,"~", grid_x))) +
ggtitle(paste0("NET LOSS RATIO - ", toupper(price))) +
ylab(" ") + xlab("Number Insureds") +
geom_hline(yintercept=100, linetype="dashed", color = "dodgerblue4") +
ylim(0,1000) +
xlim(0,500) +
theme(strip.background = element_rect(fill=fill, size=1.5, linetype="solid"))
}
but it only works if one specifies the iput parameter using quotes, like this:
test <- getLRplot("region1", "size", "experience")
I want to avoid using quotes, so one can say:
test <- getLRplot(region1, size, experience)
but this return an error:
Error in getLRplot(region1, size, experience) :
object 'experience' not found
I have tried to do different thing inside the function like: price = enquo(price)
or price = c(price)
etc but i always get an error. I am aware this has to do with the quotes, but i cannot figure out how to solve this?