2015-11-16 58 views
2

我正在使用ggplot製作一個圖形,圖例水平位於圖上。我的變量有多個圖例(即顏色,形狀,線型)。R ggplot傳說:關鍵標籤的位置標籤

+ theme(legend.position = 'top', legend.direction = "horizontal", legend.box = "horizontal") 

反正是有把每個圖例的標題上面的描述,而不是在一旁

和/或

地點標籤文本上方的關鍵。

+0

瞭解如何創建完整的示例,請。 –

回答

5

像是爲每種審美添加guides(...)

ggplot(diamonds, aes(depth, price, color = cut)) + 
    geom_point() + 
    theme(legend.position = 'top', 
     legend.direction = "horizontal", 
     legend.box = "horizontal") + 
    guides(color = guide_legend(title.position = "top", 
           # hjust = 0.5 centres the title horizontally 
           title.hjust = 0.5, 
           label.position = "bottom")) 

enter image description here

+0

完美。我發現的一切都將我引向主題而不是指導。 –