rplotgraphic

R: Speical case of mathematical annotation


I want to set a title with mathematical symbol. In detail I want to write, that k is an element of [1;12]. I dont know how to do it.

My approach is the following one:

plot(1:10, main = expression(k %in% w)) 

But I can't reach to remove the w by [1;12].

Maybe someone can help me


Solution

  • You could hard code the title like this:

    plot(1:10, main = expression(k %in% group("[", "1;12", "]")))
    

    Or say you want the 1 and 12 to come from values in a variable. You can use bquote as in these examples that I made up:

    w <- c(1, 12)
    plot(1:10, main = bquote(k %in% group("[", list(.(w[1]), .(w[2])), "]")))
    
    z <- 1:12
    plot(1:10, main = bquote(k %in% group("[", .(min(z)) * ";" * .(max(z)), "]")))