2012-08-30 39 views
2

我一直在尋找這一段時間。我的傳奇正在走出圖表區域。有沒有辦法在ggplot2中垂直對齊圖例?ggplot vertical justify legend

ggplot(x, aes(x=TimeStamp, y=Average, colour=Host, group=Host)) 
    + geom_point(size=0.4) 
    + geom_smooth(method="lm", se=FALSE, size=1) 
    + theme_bw() 
    + xlab("Date") 
    + ylab("% CPU Utilization") 
    +opts(axis.title.x = theme_text(face="bold", colour="#990000"), axis.text.x = theme_text(angle=90), axis.title.y = theme_text(face="bold", colour="#990000", angle=90),legend.key.size = unit(0.8, 'lines')) 
    + ylim(0, 100) 
    + scale_x_date(breaks = "1 week", minor_breaks = "1 day", labels=date_format("%b-%d-%y")) 
    + opts(legend.text = theme_text(colour = 'black',size = 10)) 
    + labs(colour = "Servers") 
    + guides(col=guide_legend(nrow=30)) 
+0

是不是這與你的[上一個問題](http://stackoverflow.com/q/12202683/420055)(在這種情況下,你可以簡單地更新它,而不是發佈一個新的)? – chl

回答

10

這應該工作:

ggplot(...) + theme(legend.direction='vertical',legend.box='horizontal') 

如果你想控制的傳說的絕對位置。

ggplot(...) + theme(legend.direction='vertical', 
legend.box='horizontal', 
legend.position = c(0.025,0.975), 
legend.justification = c(0, 1)) 

其中,例如,將圖例放置在圖形的左上角。