括号中的数字在ggplot中不居中

问题描述 投票:0回答:1

数字顶部对齐,并在

geom_label_repel()
中带有括号(下面的代码示例)。使用
geom_label()
时也会发生相同的行为。如何使标签中的数字位于括号的中心?

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()
r ggplot2 plot geom-text
1个回答
0
投票

我们可以使用

label.padding
参数:

library(ggrepel)
library(tidyverse)

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

© www.soinside.com 2019 - 2024. All rights reserved.