Search code examples
rexpressionplotmath

How can you use the atop function in expression()?


I need to add a line break but I am struggling with the atop function in expression(). The main is the part I would like to break into two lines.

> plot (DAC~Chlo,data=brazilw,
        pch=15,col="red",cex=0.5,
        main=expression("Fig. 3. Relationship
                        between diffuse attenuation coefficient at 490 nm 
                        (K"[d]*") and chlorophyll concentration at three coral
                         reef sites"),
        xlab=expression("Chlorophyll concentration (mg "*m^{-3}*")"),
        cex.lab=0.8,
        cex.main=0.8,
        cex.axis=0.8, 
        font.main=1,
        ylim=c(0,0.3),
        xlim=c(0,3.5), 
        ylab=expression("K"[d]*"(m"*-1^{-1}*")"))

Solution

  • You did not specify, where you want to break the string, but this example should help you:

    plot(1~1, 
     main=expression(atop("bla bla bla" ~ (K[d]),
                          "bla bla bla")))
    

    enter image description here