[英]how to change strip.text labels in ggplot with facet and margin=TRUE
[英]ggplot2: change strip.text position in facet_grid plot
您可以在绘图区域内设置图例的位置,例如
... + theme(legend.justification=c(1,0), legend.position=c(1,0))
是否有类似的简单方法来更改条带文本的位置(或分组图中的因子水平)
library(reshape2); library(ggplot2)
sp <- ggplot(tips, aes(x=total_bill, y=tip/total_bill)) + geom_point() +
facet_grid(. ~ sex)
sp
( http://www.cookbook-r.com/Graphs/Facets_%28ggplot2%29/ )
在格子中,我会使用类似 strip.text = levels(dat$Y)[panel.number()] 和 panel.text(...) 之类的东西,但也可能有更清洁的方法......
谢谢,克里斯托夫
这是一种方法:
ggplot(tips, aes(x = total_bill, y = tip / total_bill)) +
geom_point() +
facet_grid(. ~ sex) +
geom_text(aes(label = sex), x = Inf, y = Inf, hjust = 1.5, vjust = 1.5) +
theme(
strip.background = element_blank(),
strip.text = element_blank()
)
但是,这并没有移动strip.text
,而是添加了一个geom_text
元素并关闭了strip.background
和strip.text
,但我认为它实现了预期的结果。
轻微除了@JasonAizkalns是添加check_overlap = T
在选项geom_text
,以避免多个相同标签的叠加。
ggplot(tips, aes(x = total_bill, y = tip / total_bill)) +
geom_point() +
facet_grid(. ~ sex) +
geom_text(aes(label = sex), x = Inf, y = Inf, hjust = 1.5, vjust = 1.5, check_overlap = TRUE) +
theme(
strip.background = element_blank(),
strip.text = element_blank()
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.