Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

R ggplot geom_label rotate label

I have a plot with labels. I wanted the bounding background box on the label so I switched from using geom_text to geom_label. When I was using the geom_text option I had my angle = 90. Is there a way to do that with geom_label? Or an alternative method to labeling with a background?

Here is some sample code to play with:

ggplot(data = iris,
       aes(x = Sepal.Width, y = Petal.Length)) + geom_point(size = 10)+ 
        geom_label(data = iris,
                         aes(x = Sepal.Width, y = Petal.Length, label = Species),alpha=0.5)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

According to the docs

Currently geom_label() does not support the check_overlap argument or the angle aesthetic.

An alternative would be to use ggtext::geom_richtext:

library(ggplot2)

ggplot(
  data = iris,
  aes(x = Sepal.Width, y = Petal.Length)
) +
  geom_point(size = 10) +
  ggtext::geom_richtext(aes(label = Species), alpha = 0.5, angle = 90)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading