Insert function variable into graph title

34,824

You should use pasteinstead of c:

plot(..., main=paste("Jaccard vs. Tsim for depths",  min.depth, "to",max.depth,"m", sep=" "))

With c you create a vector of strings (hence the stacking), with paste you concatenate them into one single string.

Share:
34,824
Elizabeth
Author by

Elizabeth

I am a reef ecologist who occasionally dabbles in R.

Updated on July 09, 2022

Comments

  • Elizabeth
    Elizabeth almost 2 years

    I have a function with two input variables

    min.depth<-2  
    max.depth<-5
    

    the function produces a plot. How can I insert the input variables into the title?

    I have tried:

    plot.a<-plot(plt.a$"Traits",plt.a$"Species",xlab="Site similarity by traits (Tsim)",
                 ylab="Site similarity by species (Jaccard)",
                 main=c("Jaccard vs. Tsim for depths", min.depth, "to",max.depth,"m")
    

    While this does insert the input variable correctly it also causes the title to stack as follows:

    Jaccard vs. Tsim for depths  
    2  
    to  
    5  
    m 
    

    Any ideas on how to avoid this stacking?