Home > Software design >  R ggplot geom_label rotate label
R ggplot geom_label rotate label

Time:09-10

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)

CodePudding user response:

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)

  • Related