2016-09-27 94 views
2

我正在嘗試縮小我的長軸標籤之間的間距。我基地R圖形我應該使用lheight,但似乎沒有影響ggplot。是否有一個ggplot等價物?ggplot中文本的線高度間距

玩具例子來說明這個問題:

library("tidyverse") 
df0 <- mtcars %>% 
    rownames_to_column("car") %>% 
    mutate(car = str_wrap(car, width = 10)) 

ggplot(data = df0, aes(x = car, y = mpg)) + 
    geom_bar(stat = "identity") + 
    coord_flip() 

# has no effect 
par(lheight = 0.5) 
ggplot(data = df0, aes(x = car, y = mpg)) + 
    geom_bar(stat = "identity") + 
    coord_flip() 

enter image description here

+3

參見'ggsave','png' /'jpg'和/或與'主題指定文本的大小(axis.text = element_text(大小= ..)' – Jaap

+0

@ ProcrastinatusMaximus據我所知,這會減少文本的大小(以及行間距),而不僅僅是行之間的空間大小......這就是我所追求的 – gjabel

+0

如果我們在「避免重疊「,我們可以左對齊多個行名稱,並右對齊單行名稱? – zx8754

回答

4

你可能會尋找選項的組合。最接近lheight可能設置lineheightelement_text。我也使字體更小,只是爲了顯示選項。

ggplot(data = df0, aes(x = car, y = mpg)) + 
    geom_bar(stat = "identity") + 
    coord_flip() + 
    theme(axis.text.y = element_text(lineheight = 0.5 
            , size = 6)) 

enter image description here