4

I made this 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 to erase the line in the Time legend which appears inside the colors. And at the same time I want a transparent background in the Recommendations legend.

zx8754
  • 52,746
  • 12
  • 114
  • 209
Guillermo
  • 43
  • 3
  • 1
    How to remove the lines is described e.g. [here](http://stackoverflow.com/questions/29941900/remove-lines-from-color-and-fill-legends/29944868#29944868). I think you can apply the same principle for the "Recommendations" legend. You may search SO for `override.aes` for additional examples. – Henrik May 08 '15 at 08:56

1 Answers1

0

you can try this with little modification from your code and help from @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)))
#

enter image description here

Mamoun Benghezal
  • 5,264
  • 7
  • 28
  • 33