2013-04-08 48 views
0

我有看起來像this的數據。如何放大面板以包含長傳說標籤

我當前的代碼在這裏

library(ggplot2) 
library(RColorBrewer) 
pal <- c(brewer.pal(8,"Dark2"),brewer.pal(12,"Paired")); 
dat<-read.table("http://dpaste.com/1051194/plain/",header=TRUE) 
dat.sub <- data.frame(dat$Function,dat$Freq) 
ggplot(dat.sub,aes(dat.Freq,color=dat.Function),shape=dat.Function)+ stat_density(geom="path",position="identity",size=0.5) 

產生類似下圖: enter image description here

注意圖例文本的長度引起的主要情節被擠壓。 處理這個問題的最好方法是什麼,這樣數字顯得正常 ,圖例也顯示了完整性?

+0

更寬的設備 – James 2013-04-08 14:30:12

+0

你如何做到這一點的情節? – neversaint 2013-04-08 14:31:17

+1

如果以交互方式使用窗口,則可以展開該窗口,或者使用'ggsave'的'width'參數設置設備的大小。 – James 2013-04-08 14:33:12

回答

5

一種可能性是將圖例置於圖下,然後將標籤排列在兩列中。

ggplot(dat.sub,aes(dat.Freq,color=dat.Function),shape=dat.Function)+ 
    stat_density(geom="path",position="identity",size=0.5)+ 
    theme(legend.position="bottom",legend.direction="vertical")+ 
    guides(color=guide_legend(ncol=2)) 

enter image description here