Adjust plot title (main) position

前端 未结 3 1457
眼角桃花
眼角桃花 2020-12-02 18:18

I have been unable to find a way to adjust the (vertical) distance between plot and main title in R using par. In this example:

plot(1, 1, main = \"Title\")
         


        
相关标签:
3条回答
  • 2020-12-02 18:49

    We can use title() function with negative line value to bring down the title.

    See this example:

    plot(1, 1)
    title("Title", line = -2)
    

    enter image description here

    0 讨论(0)
  • 2020-12-02 19:02

    To summarize and explain visually how it works. Code construction is as follows:

    par(mar = c(3,2,2,1))
    barplot(...all parameters...)
    title("Title text", adj = 0.5, line = 0)
    

    explanation:

    par(mar = c(low, left, top, right)) - margins of the graph area.
    
    title("text" - title text
          adj  = from left (0) to right (1) with anything in between: 0.1, 0.2, etc...
          line = positive values move title text up, negative - down)
    

    0 讨论(0)
  • 2020-12-02 19:05

    Try this:

    par(adj = 0)
    plot(1, 1, main = "Title")
    

    or equivalent:

    plot(1, 1, main = "Title", adj = 0)
    

    adj = 0 produces left-justified text, 0.5 (the default) centered text and 1 right-justified text. Any value in [0, 1] is allowed.

    However, the issue is that this will also change the position of the label of the x-axis and y-axis.

    0 讨论(0)
提交回复
热议问题