Friday 25 March 2016

R ggplot2 vjust and hjust

What do hjust and vjust do when making a plot using ggplot?

Imagine that the text is bordered within a box.

hjust=0 places the reference position coinciding with the left side of the box. hjust=n (n>0) shifts the box to the left by n*(box width) in relation to the reference position. hjust=n (n<0) shifts the box to the right by n*(box width)  from the reference position.

vjust=0 place the reference position coinciding with the bottom side of the box. vjust=n (n>0) shifts the box down in relation to the reference position by n*(box height). vjust=n  (n<0) shifts the box up  from the reference position by n*(box height).

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Cited from the book "ggplot2 Elegant Graphics for Data Analysis"

Justification of a string (or legend) defines the location within the string that is placed at the given position. There are two values for horizontal and vertical justification. The values can be:
  • A string: "left", "right", "centre", "center", "bottom", and "top".
  • A number between 0 and 1, giving the position within the string (from bottom-left corner).

No comments:

Post a Comment