I am attempting to create a function, which would make me easily plot data by a given year from dataframe with data for many years. I have succeeded in doing this. However, I also want the given year to be shown in the title, but can't figure out how to put an argument into the title string.
For simplicity, I will just show a mock function:
my_plot <- function(x){
v1 <- x:10
return(plot(v1, main = "The year of ...y..."))
}
my_plot(x=4)
How do I replace ...y... with an function argument?
Best, Rikki
CodePudding user response:
You can use paste()
to combine two different strings:
my_plot <- function(x, year){
v1 <- x:10
return(plot(v1, main = paste("The year of", year))
}
my_plot(x=4)