如何将geom_label_repel映射到ggplot2中的颜色

我对数据集进行箱线图绘制。引入了一个新人员,我想使用geom_label_repel在现有数据集上绘制该人员。但是,未考虑颜色(可能是因为其数据集不同)。

有没有办法用旧数据集中的颜色绘制Lisa?

library(ggplot2)
library(ggrepel)

xDF <- data.frame(age=c(20,22,25,27,44, 34, 28, 32) ,
                 sex = c("F", "F", "M", "F", "M", "M", "F", "M"),
                 Home_city =c("NY", "LA","NY", "LA", "LA", "LA","NY","NY") )

new_person <- data.frame(age=40, sex="F", Home_city="NY", name= "Lisa")

 ggplot(data=xDF, aes(x=Home_city, y=age, color=sex))+
     geom_boxplot()+
     geom_label_repel(data=new_person, aes(x=Home_city, y=age, color=sex, label=name),
               box.padding   = 0.35, 
               point.padding = 0.5,
               segment.color = 'grey50')
评论