i made plot:
#data sal<-data.frame(x=factor(c(2,2,1,1),labels=c('house','work'))) sal$id<-factor(c(2,1,2,1),labels=c('t0','t1')) sal$val<-c(305,280,290,180) sal$lim1<-c(75,75,150,150) sal$lim2<-c(150,150,300,300) #plot p<-ggplot(sal,aes(id,y=val,fill=id))+ geom_bar(stat="identity",position="dodge",width=.75)+ scale_fill_brewer(palette='set1',type='qual',name='time')+ theme(axis.title.x=element_blank(), axis.title.y=element_blank(), panel.background=element_rect(fill="transparent",colour=na), panel.grid.minor=element_line(colour='grey',linetype=2), panel.grid.major=element_line(colour='grey'), plot.background=element_rect(fill="transparent",colour=na), axis.ticks=element_blank(), axis.text.x=element_blank(), legend.position='bottom')+ geom_hline(aes(yintercept=lim1,lty='lim1'),lwd=1,show_guide=t)+ geom_hline(aes(yintercept=lim2,lty='lim2'),lwd=1,show.guide=t)+ scale_linetype_manual(name="recommendations",values=1:2, labels=c('r1','r2')) p+facet_grid(.~x)+theme(strip.background=element_rect(colour='white',fill='transparent'), strip.text.x=element_text(size=15,face='bold'))
i need erase line in time
legend appears inside colors. , @ same time want transparent background in recommendations
legend.
you can try little modification code , @henrik
ggplot(sal,aes(x=id,y=val,fill=id))+ geom_bar(stat="identity",position="dodge",width=.75) + scale_fill_brewer(palette='set1',type='qual',name='time')+ theme(axis.title.x=element_blank(), axis.title.y=element_blank(), panel.background=element_rect(fill="transparent",colour=na), panel.grid.minor=element_line(colour='grey',linetype=2), panel.grid.major=element_line(colour='grey'), plot.background=element_rect(fill="transparent",colour=na), axis.ticks=element_blank(), axis.text.x=element_blank(), legend.position='bottom')+ facet_grid(.~x)+theme(strip.background=element_rect(colour='white',fill='transparent'), strip.text.x=element_text(size=15,face='bold'))+ geom_hline(aes(yintercept=lim1,lty='lim1'),lwd=0,show_guide=t)+ geom_hline(aes(yintercept=lim2,lty='lim2'),lwd=0,show.guide=t)+ geom_hline(aes(yintercept=lim1,lty='lim1'),lwd=1,show_guide=t)+ geom_hline(aes(yintercept=lim2,lty='lim2'),lwd=1,show.guide=f)+ scale_linetype_manual(name="recommendations",values=c(3,1), labels=c('r1','r2'))+ theme(legend.key = element_rect(fill = "transparent"))+ guides(fill = guide_legend(override.aes = list(linetype = 0)), color = guide_legend(override.aes = list(linetype = 0))) #
Comments
Post a Comment