【发布时间】:2019-08-01 02:36:28
【问题描述】:
我正在为 ggpubr 中的传奇位置而苦苦挣扎。我知道我可以修改图例位置 p.e.通过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"))无效。