2017-02-22 4 views
2

私はggalluvialを使用して、学期を超えた学生の学問の経過を追跡し、時間の経過とともにどのようにカリキュラムを変更するかを見ていきます。個々のパスを沖積グラフにマッピングするにはどうすればよいですか?

これは私のデータセットのサンプルです:

structure(list(id = c("1", "2", "6", "8", "9", "10", "11", "12", 
"14", "15", "1", "2", "6", "8", "9", "10", "11", "12", "14", 
"15", "1", "2", "6", "8", "9", "10", "11", "12", "14", "15", 
"1", "2", "6", "8", "9", "10", "11", "12", "14", "15", "1", "2", 
"6", "8", "9", "10", "11", "12", "14", "15", "1", "2", "6", "8", 
"9", "10", "11", "12", "14", "15", "1", "2", "6", "8", "9", "10", 
"11", "12", "14", "15", "1", "2", "6", "8", "9", "10", "11", 
"12", "14", "15"), 
curr = c("CURR1", "CURR1", "CURR1", "CURR1", 
    "CURR1", "CURR1", "CURR1", "CURR1", "CURR1", "CURR1", "CURR3", 
    "CURR3", "CURR3", "CURR3", "CURR3", "CURR3", "CURR3", "CURR3", 
    "CURR3", "CURR3", "CURR5", "CURR5", "CURR5", "CURR5", "CURR5", 
    "CURR5", "CURR5", "CURR5", "CURR5", "CURR5", "CURR7", "CURR7", 
    "CURR7", "CURR7", "CURR7", "CURR7", "CURR7", "CURR7", "CURR7", 
    "CURR7", "CURR9", "CURR9", "CURR9", "CURR9", "CURR9", "CURR9", 
    "CURR9", "CURR9", "CURR9", "CURR9", "CURR11", "CURR11", "CURR11", 
    "CURR11", "CURR11", "CURR11", "CURR11", "CURR11", "CURR11", "CURR11", 
    "CURR13", "CURR13", "CURR13", "CURR13", "CURR13", "CURR13", "CURR13", 
    "CURR13", "CURR13", "CURR13", "CURR15", "CURR15", "CURR15", "CURR15", 
    "CURR15", "CURR15", "CURR15", "CURR15", "CURR15", "CURR15"), 
     value = c("ISDS", "ISDS", "GBUS", "ISDS", "GBUS", "ISDS", 
     "ACCT", "GBUS", "ITF", "MGT", "ISDS", "ISDS", "GBUS", "ISDS", 
     "MKT", "ISDS", "ACCT", "GBUS", "ITF", "MGT", "ISDS", "ISDS", 
     "ISDS", "ISDS", "MKT", "ISDS", "ACCT", "GBUS", "ISDS", "MGT", 
     "ISDS", "ISDS", "ISDS", "ISDS", "ISDS", "ISDS", "ACCT", "GBUS", 
     "ISDS", "ISDS", "ISDS", "ISDS", "ISDS", NA, "ISDS", "ISDS", 
     "ACCT", "ISDS", "ISDS", "ISDS", "ISDS", "ISDS", "ISDS", "ISDS", 
     "ISDS", "ISDS", "ISDS", "ISDS", "ISDS", "ISDS", "ISDS", NA, 
     "ISDS", "ISDS", "ISDS", NA, "ISDS", "ISDS", "ISDS", "ISDS", 
     "ISDS", NA, "ISDS", "ISDS", "ISDS", NA, "ISDS", "ISDS", "ISDS", 
     NA)), class = "data.frame", row.names = c(NA, -80L), .Names = c("id", 
    "curr", "value")) 
  • ID =学籍
  • CURR =学期ID私はマッピングしたい
  • 値=カリキュラムのID

  1. CURR x軸(時間変数)、y軸の異なる高さに

  2. value

  3. 流れの幅にそれぞれCURRためvalueのカウント

ダイアグラムは、どのカリキュラムが時間の経過とともに「どのように」流れているかを示します。

これは、x軸は大丈夫に見えますが、weightは時間をかけてカリキュラムの異なる重みを反映しても私はありませんかなりオフ

ggplot(as.data.frame(ff2), 
     aes(x=curr, axis1=value, group=id)) + 
    geom_alluvium(aes(fill = value)) 

enter image description here

である、私がこれまで持っているものです生徒の「流れ」に従うことができます。

+0

私の最初の提案は、変数を順序付けることです。 CURRを数値またはアルファベット順の文字列に変更します。 'ff2 $ curr < - as.numeric(gsub(" CURR "、" ff2 $ curr)) ' 値については、y軸の高さがどういう意味なのかよくわかりません。 – jesstme

+0

@jesstme y軸にカリキュラム名を載せたいと思います。順序付けに関しては、私は 'ordered'を使うことができますが、それは問題を解決しません。 – Dambo

答えて

2

申し訳ありません。私は、ダイアグラム全体にまたがる完全な「alluvia」ではなく、複数の軸の間に「フロー」をプロットするための別個のgeomを含む実験ブランチと、新しいパラメータの束をマージしました。これにより、ff2structure()コールが割り当てられていると仮定すると、次のコードを使用して、記述しているプロットの種類が可能になります。特に一貫した方法でNA秒を処理するために、この必要性を指摘して

# keep the values of 'curr' in their proper order 
ff2$curr <- factor(ff2$curr, levels = unique(ff2$curr)) 
ggplot(ff2, aes(
    # position aesthetics: 
    # 'x' as in 'geom_bar()' 
    # 'stratum' and 'alluvium' specific to ggalluvial 
    x = curr, stratum = value, alluvium = id, 
    # apply 'fill' colors to both flows and strata 
    fill = value 
)) + 
    # flow parameters: 
    # 'lode.guidance' says how to arrange splines in each stratum 
    # 'aes.flow' says which axis determines flow aesthetics 
    geom_flow(lode.guidance = "rightleft", aes.flow = "forward") + 
    geom_stratum() + 
    # include text labels at each stratum 
    geom_text(stat = "stratum") 

ありがとう!

0

以下を試してください。それは豪華ではありませんが、それは動作します。ベースのグラフィックスを使用して少し掃除することができます。

あなたがまだの場合は、以下のパッケージをインストールし、その後、それらをロード:

library(alluvial) 
library(tidyr) 

編集したデータ:学生によって

ff2$value[is.na(ff2$value)] <- "None" # Replace NAs with a category so they're not lost 
ff2$curr <- as.numeric(substr(ff2$curr, 5, nchar(ff2$curr))) # Change your term labels to numeric for easy & correct ordering 
ff3 <- spread(ff2, curr, value, fill = "None") #spread your df from long to wide format 

色チャートを、より簡単に追跡するために時間をかけて:

cl <- colors(distinct = TRUE) 
color_palette <- sample(cl, length(ff3$id)) 

プロット:

alluvial(ff3[,2:9], 
     freq = 8, 
     col = color_palette, 
     blocks = T, 
     xw = 0.2,# makes the ribbons a bit wavier 
     axis_labels = c("Term1","Term2", "Term3","Term4","Term5","Term6", "Term7","Term8")) 
関連する問題