GGplot2 结合 Guide_legend 个参数

GGplot2 in combination with Guide_legend arguments

默认情况下,ggpubr 包中的

theme_pubr 创建图例,标题在侧面,变量水平分布。但是,我正在尝试制作一个图例,标题在顶部,物种在一栏中。

我试过使用 guides(colour=guide_legend(ncol=1))guides(colour = guide_legend(title.position = "top")) 组合在一起,但是一个似乎覆盖了另一个。谁能解释为什么会发生这种情况以及如何解决它?

使用鸢尾花数据集的示例代码。

library(ggplot2)
library(datasets)
library(ggpubr)



ggplot(iris,aes(Species, Petal.Length))+
  geom_point(aes(colour= Species))+
  theme_pubr()+
  labs_pubr()+ 
  guides(colour=guide_legend(ncol=1))+
  guides(colour = guide_legend(title.position = "top"))

提前致谢,

斯图尔特

您可以在一个函数中同时使用两个参数,而不是创建两个相互覆盖的函数

guides(colour=guide_legend(title.position = "top", ncol=1))