ggplot
で次のように縦並びのfacetグラフを作りたいとします。
library(ggplot2) ggplot(diamonds, aes(carat, ..density..)) + geom_histogram(bins = 20) + facet_wrap(~cut, ncol = 1) + coord_flip() ggsave("diamonds_cutcarat_facet.png", width = 5, height = 2.75)

見るに値しないこのグラフのfacetのラベル(Fair
とかGood
とか)をサイドに置きたいと思うのは自然でしょう。
そのためにはfacet_wrap
のオプションのstrip.position
を使います。
ggplot(diamonds, aes(carat, ..density..)) + geom_histogram(bins = 20) + facet_wrap(~cut, ncol = 1, strip.position = "right") + coord_flip() ggsave("diamonds_cutcarat_facet_right.png", width = 5, height = 2.75)

そうすると今度はラベルを配置する隙間が少なくてグラフの大きさ次第ではうまくラベルが表示できません。
これを回避するためにはラベルの方向を変更したい。
これはtheme
でstrip.text.y
オプションを使って下記のように設定することができます。
ggplot(diamonds, aes(carat, ..density..)) + geom_histogram(bins = 20, color = "black") + facet_wrap(~cut, ncol = 1, strip.position = "right") + coord_flip() + scale_x_continuous(minor_breaks = NULL) + theme(strip.text.y = element_text(angle = 0))

これでとりあえずは他人に見せることが可能なグラフになりました。