2016-07-28 497 views

回答

1

你可以摆脱使用指南()你的问题,并指定标题的位置。

library(ggplot2) 
xy <- data.frame(x=1:10, y=10:1, type = rep(LETTERS[1:2], each=5)) 

plot <- ggplot(data = xy)+ geom_point(aes(x = x, y = y, color=type)) + 
     theme(legend.position = 'bottom') + 
     guides(colour = guide_legend(title.position = "top")) 

plot 

虽然这是旧的,我注意到,这个答案 Legend title position in ggplot2是好的呢,即使是GGPLOT2现在很多版本在0.9以上。 我注意到不再需要调用库(尺度)。 希望这会有所帮助

+0

谢谢!我知道如何用opts做到这一点,这已经被弃用了一段时间。我无法弄清楚定位是在颜色中确定的 –