2016-09-25 4 views
0

なぜ私のプロットのファセットの名前が次のコードに表示されないのか分かりません。誰かがヒントとして歓迎されるならば。私は、コードを実行するとファセット名をggplot2に表示

data <- data.frame(id = rep(c("Large choice", "Low prices", "Service quality", "Product quality", "Convenience"), 4), 
        variable = rep(factor(c("OfficeStar", "Paper and Co", "Office Equipment", "Supermarket"), 
        levels = c("OfficeStar", "Paper and Co", "Office Equipment", "Supermarket")), each = 5), 
        value = sample(30, 20), 
        focus = as.factor(c(rep(1,5), rep(0, 15)))); 
nb_col <- 3 

> head(data, 10) 
     id    variable  value focus 
     Large choice OfficeStar  5.2  1 
     Low prices OfficeStar  2.1  1 
    Service quality OfficeStar  4.2  1 
    Product quality OfficeStar  3.7  1 
     Convenience OfficeStar  2.7  1 
     Large choice Paper and Co 4.4  0 
     Low prices Paper and Co 4.5  0 
    Service quality Paper and Co 2.3  0 
    Product quality Paper and Co 2.6  0 
     Convenience Paper and Co 1.4  0 

ggplot(data = data, aes(x = variable, y = value, fill = focus)) + 
    geom_bar(stat = "identity") + 
    facet_wrap(~id, ncol = nb_col, drop = FALSE) + 
    scale_fill_manual(values = c("#77bb77", "#5599bb")) + 
    coord_flip() + 
    theme(axis.title.x = element_blank(), 
      axis.title.y = element_blank(), 
      panel.grid = element_blank(), 
      legend.position = "none") 

を私が手:

最初のファセットは、例えば、ここで大きな選択肢と命名されなければなりません。 私はデータテーブルがユーザー入力を介して取得されているので、私はそれらが文字列であることはわかっていますが、どのIDがどのように見えるかはわかりません。

私は誰もいなかったので、idにレベルを適用しようとしましたが、うまくいかず、labeller関数を使用しようとしましたが、何もしませんでした。

> sessionInfo() 
R version 3.3.1 (2016-06-21) 
Platform: x86_64-w64-mingw32/x64 (64-bit) 
Running under: Windows >= 8 x64 (build 9200) 

locale: 
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252 LC_NUMERIC=C       
[5] LC_TIME=English_United States.1252  

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

other attached packages: 
[1] gridExtra_2.2.1 ggrepel_0.5  GMD_0.3.3  cluster_2.0.4 proto_0.3-10 lme4_1.1-12  Matrix_1.2-6 MASS_7.3-45  nnet_7.3-12  
[10] sendmailR_1.2-1 RODBC_1.3-13 scales_0.4.0 ggplot2_2.1.0 gplots_3.0.1 stringr_1.1.0 digest_0.6.10 reshape2_1.4.1 

loaded via a namespace (and not attached): 
[1] Rcpp_0.12.6  magrittr_1.5  splines_3.3.1  munsell_0.4.3  lattice_0.20-33 colorspace_1.2-6 minqa_1.2.4  plyr_1.8.4   
[9] caTools_1.17.1  tools_3.3.1  nlme_3.1-128  gtable_0.2.0  KernSmooth_2.23-15 gtools_3.5.0  nloptr_1.0.4  base64enc_0.1-3 
[17] bitops_1.0-6  labeling_0.3  gdata_2.17.0  stringi_1.1.1  
+0

あなたは何について不思議ですか? –

+1

ああ、申し訳ありませんがデータを作成できませんでした。変更されたver。変数= rep(ファクタ(c))、データ品質(data quality)、データ品質(data quality) 「OfficeStar」、「Paper and Co」、「Office Equipment」、「Supermarket」))、レベル= c(「OfficeStar」、「Paper and Co」、「Office Equipment」、「Supermarket」))、それぞれ= 5)、値=サンプル(30,20)、フォーカス= as.factor(c(rep(1,5)、rep(0,15)))); nb_col < - 3'しかし、私はあなたの 'ggplot'コードを実行すると再現できません。 – cuttlefish44

+0

再現性のないものとしてクローズする投票。 – Jaap

答えて

0

[OK]をクリックします。問題がどこにあるかを確認しました。デフォルトはfacet_wrapswitch = "x"あるので、それは可能性

theme_update(strip.text.x = element_blank()) 

:明らか部分のコードで、あなたは我々がどこかを知らせる前に呼び出された別のファイル内のコードの一部を持っていたこと...

を見つけることができませんでしたうまくいかない。しかし、私は次のことを行うと、それは正常に動作します:

ggplot(data = data, aes(x = variable, y = value, fill = focus)) + 
     geom_bar(stat = "identity") + 
     facet_wrap(~id, ncol = 3, drop = FALSE, labeller = "label_value", switch = "y") + 
     coord_flip() + 
     theme(axis.title.x = element_blank(), 
      axis.title.y = element_blank(), 
      panel.grid = element_blank(), 
      legend.position = "none") 
関連する問題