Move Title to Align with Y Axis Text

ggplot2

#1

How I would I go about moving the title of this plot to sit more above the y-axis text and not where the plot panel begins? Also how I would I move the caption to the right to sit more in the bottom-right hand corner of the plot?


#2

Could you please post the code you're using to generate the plot, it'll be a bit easier to add to what you've got once we see what's there.

Generally speaking, you can move the text horizontally using hjust as described at the link below:
http://ggplot2.tidyverse.org/articles/ggplot2-specs.html#text


#3

Note that hjust is defined as [0, 1] based on the extent of the data area of the plot, not based on the outer edges of the plot background. So currently, your title has hjust = 0 and your caption has hjust = 1. You can use values outside of [0, 1] to move the title further left (e..g, hjust = -0.25) or further right (e.g., hjust = 1.25), but because the scale is relative and still anchored to the left and right edges of the plotting area, you will have to hand tweak hjust to get your title to align with your y-axis labels or the right edge of your plot background. You will have to repeat the tweaking if the axis labels or legend changes, since these influence the width of the plot margins.

For a different approach, see the cowplot package, whose ggdraw() function defines a transparent layer above (or below) the plot where you can add absolutely positioned annotations:
https://cran.r-project.org/web/packages/cowplot/vignettes/introduction.html

This SO question may also be helpful:


#4

Thank you, this was exactly what I was looking for. I think I needed less help with my code and more just knowing how to describe what I was trying to do. The hjust wasn't working for me because of the relative size thing, this worked beautifully.