ggplot

2013-08-23 21 views
29

में बहु कॉलम किंवदंती बनाना मेरे पास निम्न स्क्रिप्ट है, जो मान लीजिए जिसमें दो कॉलम किंवदंती के साथ साजिश तैयार की गई है।ggplot

#!/usr/bin/Rscript 
library(ggplot2) 
library(plyr) 
library(reshape2) 
library(scales) 

file <- "http://dpaste.com/1354089/plain/"; 
dat <-read.table(file,header=TRUE); 
datm <- melt(dat) 

# Plot them 
ggplot(datm,aes(x = variable,y = value,fill = Term)) + 
geom_bar(position = "fill") + 
scale_y_continuous(labels = percent_format())+ 
theme(legend.direction ="vertical",legend.position = "bottom")+ 

guides(color=guide_legend(ncol=2))+ # this doesn't seem to work 

ggsave(file="~/Desktop/test.pdf",width=11,height=11) 

लेकिन यह इस आंकड़े बनाता बजाय enter image description here

मैं कैसे इसे सही ढंग से कर सकते हैं?

उत्तर

60

आप सही सौंदर्य के लिए गाइड नियुक्त करना होगा और आप को भरने के लिए इस्तेमाल किया:

guides(fill=guide_legend(ncol=2)) 

और तुम geom_bar

+0

+1 संक्षिप्त जवाब के लिए के साथ चेतावनी का ध्यान रखना चाहिए। कोई सुझाव, चेतावनी को कैसे हल करें? – neversaint