去掉两个图例中的线条和背景

Remove the line and the background in the two legends

我做了这个情节:

#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'))

我需要擦除出现在颜色内的 Time 图例中的线条。同时我想要 Recommendations 图例中的透明背景。

您可以在@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)))
#