同时设置分面标记位置和 strip.text.y 时角度不生效
最近在做peak reads 分布图时遇到一个问题,分面后同时设置分面标记的位置和分面文字的角度(strip.text.y= element_text( angle = 0))时文字角度无法生效。
解决办法:将 strip.text.y 改为 strip.text.y.left
ggplot2::scale_y_continuous(expand = c(0,0)) + # position = "right",
# facet_wrap(.~sample, ncol = 1, scales = 'fixed', strip.position = 'left') +
# facet_grid(sample ~ . , scales = "fixed",switch='y') +
facet_grid(vars(sample), scales = "fixed", switch='y') +
theme_classic() + theme(strip.placement = 'outside',
strip.background = element_blank(),
strip.text.y.left = element_text(size=10, angle = 0))
背后逻辑解答:
主题元素有一个层次结构:
strip.text inherits from text
strip.text.y inherits from strip.text
strip.text.y.left(右)继承自strip.text.y。
主题中的“继承”意味着,当子对象中缺少父对象的属性时,子对象的属性将由父对象的属性填充。
如果使用默认主题计算theme_get()$strip.text.y,您将看到angle是-90:未缺失。因此,每当你在父strip.text中设置一些东西时,strip.text.y的角度会覆盖父角度。Kara Woo曾在演讲中讨论了这种问题。