9

Rでggplotを使用して、facet_wrapでいくつかの条件をプロットしています。縦軸のプロット名を上ではなく右に配置したいと思います。

これは例です:

library(ggplot2)
dat<- data.frame(name= rep(LETTERS[1:5], each= 4), value= rnorm(20), time= rep(1:5, 4))
gg<- ggplot(data= dat, aes(x= time, y= value)) +
    geom_point() +
    facet_wrap(~ name, ncol= 1)

ここに画像の説明を入力 ここでは、プロット名 (A、B、C、D、E) が上にあります。ここのように右側に配置したいと思います。

gg + facet_grid(name ~ .)

ここに画像の説明を入力

それを行う簡単なスイッチはありますか?(オプションを使用したいので使用していませんがfacet_grid、付属しています)。nrowncolfacet_wrap

ありがとう!ダリオ

sessionInfo()
R version 3.0.1 (2013-05-16)
Platform: x86_64-apple-darwin10.8.0 (64-bit)

locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] ggplot2_0.9.3.1

loaded via a namespace (and not attached):
 [1] colorspace_1.2-4   dichromat_2.0-0    digest_0.6.4       grid_3.0.1        
 [5] gtable_0.1.2       labeling_0.2       MASS_7.3-29        munsell_0.4.2     
 [9] plyr_1.8.1         proto_0.3-10       RColorBrewer_1.0-5 Rcpp_0.11.0       
[13] reshape2_1.2.2     scales_0.2.3       stringr_0.6.2      tools_3.0.1       
4

2 に答える 2

1

ファセットの左側にファセット ラベルを配置したい場合は、y 軸が x 軸になり、x 軸が y 軸になる簡単な解決策があります。

library(ggplot2)
library(gridExtra)
library(gridGraphics)

# standard plot, facet labels on top
ggplot(diamonds) + 
  aes(x = carat, y = price) + 
  geom_point() + 
  facet_wrap( ~ cut)

ここに画像の説明を入力

# Use the gridExtra and gridGraphics utilities to rotate the plot.
# This requires some modifications to the axes as well.  Note the use of 
# a negative carat in the aes() call, and text modifications with theme()
grid.newpage()
pushViewport(viewport(angle = 90))
grid.draw(ggplotGrob(

  ggplot(diamonds) + 
    aes(x = price, y = -carat) + 
    geom_point() + 
    facet_wrap( ~ cut) + 
    scale_y_continuous(name = "Carat", breaks = -seq(0, 5, by = 1), labels = seq(0, 5, by = 1)) + 
    theme(axis.text.y = element_text(angle = 270), 
          axis.title.y = element_text(angle = 270), 
          axis.text.x = element_text(angle = 270))
    ))

ここに画像の説明を入力

facet_wrapラベルを回転したグラフィックの右側に移動するには、回転角度 を使用し-90ます。ただし、それはプロットの上に有効な x 軸を持つことになります。「標準」プロットの左側から右側に y 軸のラベルを移動するためのコードに取り組み、次に で示すように回転する必要があります-90

于 2015-11-02T04:13:23.600 に答える