ggplotのfacet_gridやfacet_wrapを用いた場合、垂直方向のラベルテキストが縦書きとなり直感的でないときがあります。
この場合は、ラベルテキストのアングルを横書きに変更することで、より見やすいグラフとなります。

デフォルト

特に何も指定しない場合は、次のようなグラフとなります。


library(ggplot2)

data("diamonds")
g <- ggplot(diamonds, aes(x = carat, y = price, colour = color))
g <- g + geom_point()
g <- g + facet_grid(cut ~ .)
plot(g)

垂直方向のファセットラベルテキストのアングルを変更

垂直方向のファセットラベルテキストを横書きにする場合は、次のようにtheme関数のstrip.text.y引数を指定します。


library(ggplot2)

data("diamonds")
g <- ggplot(diamonds, aes(x = carat, y = price, colour = color))
g <- g + geom_point()
g <- g + facet_grid(cut ~ .)
g <- g + theme(strip.text.y = element_text(angle = 0)) 
plot(g)

垂直方向のファセットラベルテキストを左側配置かつアングルを変更

垂直方向のファセットラベルテキストを左側に配置するには、facet_grid関数またはfacet_wrap関数の引数にswitch=”y”を指定したうえで、次のようにtheme関数のstrip.text.y引数を指定します。


library(ggplot2)

data("diamonds")
g <- ggplot(diamonds, aes(x = carat, y = price, colour = color))
g <- g + geom_point()
g <- g + facet_grid(cut ~ ., switch = "y")
g <- g + theme(strip.text.y = element_text(angle = 180)) 
plot(g)

R ggplotでファセットラベルテキストの体裁を変更する方法