Эти опции работают здесь.
С 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))
library(ggpubr)
p <- ggline(df2, "dose", "len",
linetype = "supp", shape = "supp",
color = "supp", palette = c("#00AFBB", "#E7B800"))
p + guides(colour = guide_legend(title.position = "top"))
Я не знаю почему, но если я установлю руководство для другой эстетики, положение названия легенды не изменится:
p + guides(shape = guide_legend(title.position = "top"))
p + guides(linetype = guide_legend(title.position = "top"))
Это хороший вопрос для ggplot2
экспертов.
А вот то же самое работает в ggplot2
:
library(ggplot2)
ggplot(df2, aes(x = dose, y = len, colour = supp)) +
geom_line(aes(group = supp, linetype = supp)) +
geom_point(aes(shape = supp)) +
scale_colour_manual(values = c("#00AFBB", "#E7B800")) +
theme_classic() +
theme(legend.position = "top") +
guides(colour = guide_legend(title.position = "top"))