2016-09-27 24 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