0

In the code below, how can I align title (main ="Maximum Annual Temperature Data In Celsius") to the center of the plot?

autoplot(maxtemp, xlim = c(1990,2020), xlab = "Year", ylab = "Temperature in Celsius", 
                  main ="Maximum Annual Temperature Data In Celsius", colour = "orange")
Phil
  • 7,287
  • 3
  • 36
  • 66
Kris
  • 1
  • 1
  • Welcome to Stack Overflow! You should provide a [minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). It should be [minimal, but complete and verifiable example](https://stackoverflow.com/help/minimal-reproducible-example). Your question should be clear and specific. Would you [edit] your question and add output of `dput(head(maxtemp))`? – M-- Mar 13 '20 at 23:34
  • 1
    Add this: `+ theme(plot.title=element_text(hjust=0.5))` – Edward Mar 13 '20 at 23:38
  • Excellent. It worked. Thanks. – Kris Mar 14 '20 at 00:06

1 Answers1

0

I know you can center the title if you put a wrapper around the plot and justify it in the theme():

#save your plot in a variable
p <- autoplot(maxtemp, xlim = c(1990,2020), xlab = "Year",
     ylab = "Temperature in Celsius",
     main ="Maximum Annual Temperature Data In Celsius",
     colour = "orange")

#now justify title in theme()
p +
theme(plot.title = element_text(hjust = 0.5))

Should do it...

PhilC
  • 1
  • 1