如何在使用facet_wrap时减少刻面标签之间的垂直间距? [英] how to reduce vertical spacing between facet labels when using facet_wrap?
本文介绍了如何在使用facet_wrap时减少刻面标签之间的垂直间距?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
最小示例:
library(ggplot2)
ggplot(mpg,aes(displ,hwy))+
geom_point()+
facet_wrap(〜cyl + drv)
每个面板顶部的标签有两行,我想减少两行标签文本之间的间距。
我试过了:
ggplot ($)
pre>
$(
$) b边际=边际(t = 0,r = 0,b = 0,l = 0,单位=pt)
)
)
但这并不奏效。
预先致谢。
<$> p $ p>ggplot(mpg,aes(displ,hwy))+
geom_point()+
facet_wrap(〜cyl + drv,
labeller = function(labels ){
labels < - lapply(labels,as.character)
list(do.call(paste,c(labels,list(sep =\\\
))))
})
I drawed 2d panels grouped by two factors using facet_wrap.
minimal example:
library(ggplot2)
ggplot(mpg, aes(displ, hwy)) +
geom_point() +
facet_wrap(~ cyl + drv)
The label on the top of each panel has two rows, I want to reduce the spacing between the two rows of label text. How shoud I do this correctly?
I tried:
ggplot(mpg, aes(displ, hwy)) +
geom_point() +
facet_wrap(~ cyl + drv) +
theme(
strip.text = element_text(
margin = margin(t = 0, r = 0, b = 0, l = 0, unit = "pt")
)
)
but this didn't work.
Thanks in advance.
解决方案
You could specify a labeller that puts the labels into the same strip instead of creating two strips:
ggplot(mpg, aes(displ, hwy)) +
geom_point() +
facet_wrap(~ cyl + drv,
labeller = function (labels) {
labels <- lapply(labels, as.character)
list(do.call(paste, c(labels, list(sep = "\n"))))
})
这篇关于如何在使用facet_wrap时减少刻面标签之间的垂直间距?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文