루프가있는 플롯을 생성하려고합니다.바 너비 ggplot2 geom_bar
l1<-factor(rep(letters,4))
n1<-abs(rnorm(104))*10000
b1<-rep(c("1","2","3","4","5","6","7","8"),c(2,2,11,24,11,20,33,1))
k1<-rep((rep(c("A","B","C","D"),c(2,3,4,4))),8)
my.df<-data.frame(l1,b1,k1,n1) #make a dataframe
names(my.df)<-c("letter","branch","ltrtype","number") #factor names
library(ggplot2)
branch.list<-unique(my.df$branch)
sayi<-length(branch.list) # list of factor:letters
for (i in 1:sayi) {
branch.iter<-branch.list[i]
my.df.plot<-subset(my.df,my.df$branch==branch.iter,drop=T)
my.df.plot$branch<-factor(my.df.plot$branch) #So that unused levels don't show up
my.df.plot$letter<-factor(my.df.plot$letter) #So that unused levels don't show up
my.df.plot$ltrtype<-factor(my.df.plot$ltrtype) #So that unused levels don't show up
my.df.plot$number<-as.numeric(as.character(my.df.plot$number))
my.df.plot<-data.frame(my.df.plot)
myfilename<-paste(branch.iter,".jpeg",sep="")
jpeg(file=myfilename)
cizim<-ggplot(my.df.plot,aes(letter,number,fill=ltrtype))
cizim<-cizim + geom_bar(width = 1, position = "fill", binwidth = 1) + facet_grid(ltrtype~.)
cizim<-cizim + opts(title=branch.iter)
print(cizim)
dev.off()
}
(Q1)가 때 어떻게이를 방지와 같은 모든 플롯에서 바 폭이 달라질 수 바 x 축 변화 폭의 레벨 수?
alt text http://img411.imageshack.us/i/95325388.jpg/
alt text http://img411.imageshack.us/i/91510133.jpg/
(Q2)가: i=7
R 경고 다음 줄 때 :
(데이터 $ Ymin를 == 0)) 경고 ("잘 정의되지 채울 때 Ymin를! = 0 ") : TRUE/FALSE가 필요한 누락 값
w 모자는 내가 할 수 있니?
(Q3) : 쉽게 이러한 경우에 사용되지 않는 수준을 떨어 뜨리는 방법 그래서 난
my.df.plot$branch<-factor(my.df.plot$branch)
매번를 사용하지 않아도이 있습니까?
예. 나는 모든 브랜치에 대해 막대 너비를 동일하게 유지하려고합니다. 일부 브랜치는 너무 많은 x 값 (일부는 하나만 있습니다)을 가지고 있기 때문에 하나의 거대한 막대에서부터 많은 작은 막대까지 얻을 수 있습니다. – mehmetselim
나는 여전히 모든 플롯에 대해 동일한 x 레벨을 유지하는 것이 플롯을 비교하려는 경우 가장 좋은 방법이라고 생각하지만 '대답'을 사용하여 솔루션을 포함하도록 내 대답을 편집했습니다. – Aniko