Cómo alinear a la izquierda el texto en anotar desde ggplot2


Mi ejemplo es:

qplot(mtcars$mpg) + annotate(geom = "text", x = 30, y = 3, label = "Some text\nSome more text")

¿Cómo consigo que el texto aquí esté alineado a la izquierda? Para que los 'Algunos' se alineen entre sí.

Author: kennyB, 2014-11-01

1 answers

hjust = 0 hace lo que quieres. hjust significa justificación horizontal, 0 se justificará a la izquierda, 0.5 se centrará y 1 se justificará a la derecha.

qplot(mtcars$mpg) +
    annotate(geom = "text", x = 30, y = 3,
             label = "Some text\nSome more text",
             hjust = 0)

Véase también vjust para la justificación vertical.

En ggplot2, estos argumentos están presentes cada vez que se establecen preferencias de texto. Trabajan para annotate, geom_text, o en element_text al ajustar las opciones del tema.

Si miras ?geom_text, puedes encontrar opciones de cadena de texto: "left", "middle", o "right", (para hjust), "top", "center", "bottom" para vjust, y para "inward" y "outward" que siempre se ajustarán hacia o hacia fuera del centro.


Este comportamiento es similar en muchas funciones gráficas base, como el argumento adj para par, utilizado por text(), mtext(), y title(), que puede ser vector de longitud 2 para los justificatons horizontales y verticales. También la hadj y padj argumentos a axis() para justificaciones horizontal y p erpendicular al eje.

 90
Author: Gregor,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-08-29 19:04:09