U. Mena
U. Mena

Reputation: 51

Numbers in parentheses are not centered in ggplot

Numbers are top justified with parentheses in geom_label_repel() (Example with code below). The same behavior occurs when using geom_label(). How can I get the numbers in the labels to be in the center of the parenthesis?

Example plot with geom_label_repel() (code above) showing issue

library(tidyverse)
df_cars<- 
  mtcars[2:6,] %>% 
    mutate(CarName = rownames(.),
           CarCyl = paste(CarName, " (",cyl,")",sep = ""))

ggplot(df_cars,aes(mpg,hp))+
  geom_point()+
  ggrepel::geom_label_repel(aes(label = CarCyl))+
  theme_bw()

Upvotes: 3

Views: 49

Answers (1)

TarJae
TarJae

Reputation: 79194

Update after clarification (removed first answer):

According to this answer Fonts not available in R after importing. We could set the Graphic Device for RStudio to AGG:

Tools > Global options > General > Graphics > Backend: AGG

enter image description here

library(ggrepel)
library(tidyverse)

ggplot(df_cars,aes(mpg,hp))+
  geom_point()+
  ggrepel::geom_label_repel(aes(label = CarCyl))+
  theme_bw()

enter image description here

Upvotes: 3

Related Questions