Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use angle in geom_label?

Tags:

plot

r

ggplot2

I am not sure how to use the aes angle in geom_label. I thought this code below would rotate the labels by 45, but it doesn't.

library(ggplot2)
ggplot(data = mtcars[1:4,]) +
  geom_label(aes(x = mpg, y = qsec, label=disp), angle = 45)
like image 637
Dambo Avatar asked Dec 21 '17 09:12

Dambo


2 Answers

geom_text does not produce a label. You can use ggtext::geom_richtext

library(ggplot2)
library(ggtext)
ggplot(data = mtcars[1:4,]) +
  geom_richtext(aes(x = mpg, y = qsec, label=disp), angle = 45)

Created on 2021-06-07 by the reprex package (v2.0.0)

like image 195
tjebo Avatar answered Oct 16 '22 16:10

tjebo


Obviously this does not work for geom_label but for geom_text:

ggplot(data = mtcars[1:4,]) +
  geom_text(aes(x = mpg, y = qsec, label=disp), angle = 45)

From ?geom_text

Currently geom_label does not support the rot parameter and is considerably slower than geom_text.

rot obviously refers to rotation and seems to be a deprecated parameter for angle.

like image 21
loki Avatar answered Oct 16 '22 16:10

loki