Friday, 15 April 2011

r - How to make geom_text plot within the canvas's bounds -


Using geom_text to label external points of scatter plot. By definition, these numbers are close to the canvas edges: usually there is at least one word which overlaps the canvas edge, making it useless.

Obviously this can be solved manually in the following case + xlim (c (1.5, 4.5)) :

 < Code> # test df & lt; - data.frame (word = c ("bicycle", "tricycle", "quadricycle"), n.wheels = c (2,3,4), utility = c (10,6,7)) ggplot (data = Df, aes (x = n.wheels, y = utility, label = word)) + Geom_text () + xlim (c (1.5, 4.5))   

hjust and vjust geom_text () for clipping Can help with, especially "inward" . We can:

  ggplot (data = df, aes (x = n.wheels, y = utility) , Label = word)) + geom_text (vjust = "inward", hjust = "inward")   



No comments:

Post a Comment