How to adjust title position in ggplot2

前端 未结 1 1427
你的背包
你的背包 2021-02-07 05:00

Here is the code:

require(ggplot2)
require(grid)
# pdf(\"a.pdf\")
png(\'a.png\')
a <- qplot(date, unemploy, data = economics, geom = \"line\") + opts(title=\'         


        
1条回答
  •  滥情空心
    2021-02-07 05:25

    What you are looking for is theme(plot.title = element_text(hjust = 0)). For example, using the latest version of ggplot2 and theme instead of opts we have

    a <- qplot(date, unemploy, data = economics, geom = "line") + ggtitle("A") +
      theme(plot.title = element_text(hjust = 0))
    

    Alternatively, staying with opts

    a <- qplot(date, unemploy, data = economics, geom = "line") + 
      opts(title = "A", plot.title = element_text(hjust = 0))
    

    enter image description here

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