2016-07-28 484 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做到這一點,這已經被棄用了一段時間。我無法弄清楚定位是在顏色中確定的 –