2017-04-25 92 views
1

我正在使用ggplot來說明一組圖的結果。幾個月前,當我第一次做了我的數字(和ggplot的最新升級之前)我能夠做出這樣的:ggplot facet_grid現在切換左邊的條和刻度標記

enter image description here

但是,現在,我要重拍我的人物重新提交,和現在我已經更新到ggplot的最新版本,這是完全相同的代碼會產生:

enter image description here

供參考,這是我使用

#################### Set ggplot theme 

themebar = theme(axis.text.x = element_text(face="bold", color="black", size=rel(1), angle=0), 
      axis.title.x = element_text(size = rel(1.1), angle = 0, face="bold"), 
      axis.text.y = element_text(face="bold", color="black", size=rel(1), angle=0), 
      axis.title.y = element_text(size = rel(1.1), angle = 90, face="bold"), 
      panel.border = element_rect(linetype = "solid", colour = "black", fill=NA), 
      legend.text = element_text(size = rel(0.7), face = "bold", lineheight=0.8), 
      legend.position = "bottom", 
      legend.box = "vertical", 
      legend.background = element_rect(fill=NA, size=0.25, linetype="solid", colour ="black"), 
      legend.title = element_blank(), 
      panel.grid.major = element_line(colour="gray", linetype = "dotted"), 
      panel.background = element_rect(fill = NA), 
      strip.background = element_rect(fill = NA), 
      strip.text = element_text(size=rel(1), face="bold")) # , strip.text = element_blank() 

## labeller 
alt_sites = c(`Kolkata` = "A", `Delhi` = "B", `Dong Thap` = "C", `Kibera` = "D", `Lwak` = "E") 

ggplot(dat_2ceac_main, aes(x=wtpdol, y=prob, group=Intervention, colour=factor(Intervention))) + # 
geom_line(size=1) + 
geom_vline(aes(xintercept = 0), size=0.75, linetype=c("dotted"), show.legend=F) + 
geom_vline(aes(xintercept = vce), data=threshold, linetype=c("dashed"), show.legend=F) + 
geom_vline(aes(xintercept = ce), data=threshold, linetype=c("dotdash"), show.legend=F) + 
facet_grid(site~., switch="y", labeller=labeller(site=as_labeller(alt_sites))) + 
themebar + theme(strip.text.y = element_text(angle = 180, vjust=1), strip.switch.pad.grid=) + 
scale_colour_manual(values=Set0, labels=c("No intervention", "Routine")) + # scale_colour_hue(c=120,l=45) + 
scale_x_continuous(limits=c(0, 20000), labels=comma) + 
scale_y_continuous(limits=c(0, 1)) + 
guides(colour = guide_legend(nrow = 1, byrow=F)) + # title = "Intervention", title.position = "top", 
ylab("Probability Cost-Effective") + 
xlab("Willingness-to-pay per \ndisability-adjusted life-year averted, I$") 
代碼

回答

1

難以調試沒有看到示例數據,但嘗試添加這的themebar末:

+ strip.placement = "outside" 
+0

它的工作。謝謝,你爲我節省了很多時間。 –