我在使用ggpubr时遇到了图例位置的问题。我知道可以通过 ggpar(legend = "bottom")
来修改图例位置。但是如何将图例标题放置在图例键上方?
在 ggplot2
中,似乎可以通过 guide_legend(title.position = "top")
实现,但如何在 ggpubr
中实现呢?(感谢 @c06n 和链接: https://ggplot2.tidyverse.org/reference/guide_legend.html)。我想要结合 ggplot2
和 ggpubr
,但不确定怎么做。
示例:
df2 <- data.frame(supp=rep(c("VC", "OJ"), each=3),
dose=rep(c("D0.5", "D1", "D2"),2),
len=c(6.8, 15, 33, 4.2, 10, 29.5))
# Plot "len" by "dose" and
# Change line types and point shapes by a second groups: "supp"
p<- ggline(df2, "dose", "len",
linetype = "supp", shape = "supp",
color = "supp", palette = c("#00AFBB", "#E7B800"))
# Seems not working
ggpar(p,
linetype = guide_legend(title = "My title", title.position = "top"))
guides(colour = guide_legend(title.position = "top"))
可以工作,但例如guides(shape = guide_legend(title.position = "top"))
就不行。 - Bruno Pinheiro