2017-07-17 58 views
-1

我有一個柱狀圖,看起來像這樣: enter image description here定位聯想盒

如果我使用命令legend.position=c(1,1),legend.justification=c(1,1)然後我得到的情節是這樣的: enter image description here

但是,在這種情況下,傳說重疊劇情。我希望傳說只是向上移動而不像第一個情節那樣重疊。我該怎麼辦 ?

回答

1

你可以試試這個:

theme(legend.justification = "top") 

例子:

mtcars$gear = factor(mtcars$gear) 
mtcars$cyl = factor(mtcars$cyl) 
p = ggplot(data = mtcars, aes(x=gear, fill=cyl)) + geom_bar() 
p = p + xlab("Gears") + ggtitle("Cylinders by Gears") 
p = p + theme(legend.justification = "top") 

p 
+0

這母鹿不行 –

+0

什麼是您的代碼? – AK88

+0

哦,它的工作。其實我一起使用'legend.position = c(1,1),legend.justification =「top」',因爲它沒有正確對齊。當我只用'legend.justification =「top」'時,它已經修復了。謝謝。 –