您可以在绘图区域内设置图例的位置,例如
... + 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(...),但也可能有一个更清洁的方式...
thx,Christof
答案 0 :(得分:10)
这是一种方法:
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
,但我认为它达到了预期结果