2013-07-24 60 views
14

我希望頂部的灰色條更寬一些,因爲它的邊緣距字母的頂部和底部稍遠(strip.text - A,B,C等)。我原以爲lineheight會充當填充,但事實並非如此。有沒有辦法增加strip.text欄的高度?

ggplot(diamonds, aes(carat, price, fill = ..density..)) + 
    xlim(0, 2) + stat_binhex(na.rm = TRUE)+ 
    facet_wrap(~ color) + 
    theme(strip.text = element_text(lineheight=20)) 
+0

增加文本大小本身並不令人滿意ÿ? – alexwhan

+1

@alexwhan,增加文字大小也會增加條紋大小,但它不會改變兩個 –

+0

@RicardoSaporta的*比率*,我同意 - 我喜歡你的解決方案 – alexwhan

回答

22

首先,修改水平,使他們有斷行:

levels(diamonds$color) <- paste0(" \n", levels(diamonds$color) , "\n ") 

然後根據需要調整。例如:

P <- ggplot(diamonds, aes(carat, price, fill = ..density..)) + 
     xlim(0, 2) + stat_binhex(na.rm = TRUE)+ 
     facet_wrap(~ color) 

P + theme(strip.text = element_text(size=9, lineheight=0.5)) 

lineheight=0.5

P + theme(strip.text = element_text(size=9, lineheight=3.0)) 

lineheight=3.0

+1

延遲迴復我的部分...謝謝,骯髒的解決方案讓我們誠實哈哈,但肯定會完成工作。感謝你的幫助。 – nzcoops

1

隨着ggplot2 2.2.0,可以申請裏卡多的慣用伎倆,而無需修改數據幀,通過使用labeller

P <- ggplot(diamonds, aes(carat, price, fill = ..density..)) + 
    xlim(0, 2) + stat_binhex(na.rm = TRUE)+ 
    facet_wrap(~ color, labeller = labeller(color=setNames(paste0("\n", levels(diamonds$color), "\n"), levels(diamonds$color)))) 

P + theme(strip.text = element_text(size=9, lineheight=0.5)) 
相關問題