2016-06-19 7 views
3
require(ggplot2) 
F1 <- c(915.6425,776.2108,786.5994,656.7274,790.5350,949.0578,1053.3216,971.0848,863.6778,738.1062, 
    884.1085,904.4734,872.4323,749.6835,736.6229,773.6344,816.7553,858.8569,853.3249,891.7048, 
    850.5705,754.4007,354.7462,343.2167,337.7637,330.5004,309.0369,318.4770,335.2704,346.9049, 
    422.9287,385.5191,410.3909,416.1298,423.8248,353.9624,264.2674,199.2254,342.5222,319.3892, 
    325.5104,293.2321,289.0946,294.4882,307.3506,295.4908,344.1240,326.8981,326.8264,356.7491, 
    362.6374,459.3103,431.8374,436.6566,433.1298,430.9657,419.5703,494.0244,370.0444,439.8624, 
    296.8736,546.3018,311.0276,330.3982,346.5127,292.0111,392.9396,336.4151,310.8202) 

F2 <- c (1708.907,1703.188,1763.067,1757.835,1768.614,1651.012,1550.874,1593.289,1641.620,1238.515,1674.767, 
    1679.122,1638.291,1213.908,1793.527,1948.038,1782.379,1665.103,1646.012,1412.545,1746.250,1924.981, 
    2715.633,2593.596,2657.560,2609.197,2553.094,2712.059,2688.420,2668.596,2574.913,2576.952,2615.174, 
    2570.738,2520.431,2635.001,2726.716,2491.044,2638.541,2741.096,2708.415,2661.317,2725.348,2684.339, 
    2644.370,2724.902,2574.692,1092.502,1154.349,1698.169,1753.618,1138.324,1200.801,1592.622,1788.171, 
    1668.637,1442.751,1587.081,1871.528,1783.440,1429.906,1606.038,1318.925,1623.297,1452.331,1822.482, 
    1972.793,2017.814,1291.637) 

register<-c("ADS","ADS","ADS","ADS","ADS","ADS","ClearSpeech","ClearSpeech","ClearSpeech","ClearSpeech","ClearSpeech","ClearSpeech","ClearSpeech","IDS","IDS","IDS","IDS","IDS","IDS","IDS","IDS","IDS","ADS","ADS","ADS","ADS","ADS","ADS","ADS","ClearSpeech","ClearSpeech","ClearSpeech","ClearSpeech","ClearSpeech","ClearSpeech","ClearSpeech","IDS","IDS","IDS","IDS","IDS","IDS","IDS","IDS","IDS","IDS","IDS","ADS","ADS","ADS","ADS","ClearSpeech","ClearSpeech","ClearSpeech","ClearSpeech","ClearSpeech","ClearSpeech","ClearSpeech","ClearSpeech","ClearSpeech","IDS","IDS","IDS","IDS","IDS","IDS","IDS","IDS","IDS") 


syllable <- c ("a2", "a2", "a2", "a2", "a2", "a2", "a2", "a2", "a2", "a2", "a2", "a2", "a2", "a2", "a2", "a2", "a2", "a2", "a2", "a2", "a2", "a2", "i2", "i2", "i2", "i2", "i2", "i2", "i2", "i2", "i2", "i2", "i2", "i2", "i2", "i2", "i2", "i2", "i2", "i2", "i2", "i2", "i2", "i2", "i2", "i2", "i2", "u2", "u2", "u2", "u2", "u2", "u2", "u2", "u2", "u2", "u2", "u2", "u2", "u2", "u2", "u2", "u2", "u2", "u2", "u2", "u2", "u2", "u2") 

data2 <- cbind(syllable, register, F1, F2) 
data2 <- as.data.frame(data2) 


p<-ggplot (data2, aes (x = F1, y = F2, shape = syllable, color = register))+ 
    geom_point(aes (color = register)) 

p 

これは私のデータです。これらのポイントは、音節とレジスタの2つの要素によって分類されます。ggplot2では、散布の平均点を描き、これらの平均点を結ぶ方法は?

これを達成する方法:「レジスタ」の各レベル内で、3つの音節 "a2"、 "i2"、および "u2"の平均点を3点描画し、三角で三点。だから3つのレジスタにそれぞれ三つの三角形があるはずです。このように:

enter image description here

+0

それは 'geom_polygon'で行うことができますか? – Alex

+0

これはコード書き込み要求のようです。線を描くことや点を強調するために何を研究しましたか?あなたはまだあなたが結ぶ6つの手段を見つけるために仕事をしましたか? –

+0

コードにバグはありますか? (データ、PANEL =整数(0))): TRUE/FALSEが必要な 'missing value''これはあなたが' data2'を意味していますか?あなたの 'ggplot'呼び出しで' data'の代わりに? –

答えて

4

私が最初dplyrを使用して平均値を算出しました。プロットには元のデータを表示する1つのレイヤーが含まれています。 「平均三角形」の角にはgeom_point()(通常の点よりも大きなサイズ)がマークされています。三角形自体はgeom_polygonによって描かれました。

誰かがこれについて別の解決策を持っている場合は、私は(upvote :)を見たいと思います。

library(ggplot2) 
library(dplyr) 

F1 <- c(915.6425,776.2108,786.5994,656.7274,790.5350,949.0578,1053.3216,971.0848,863.6778,738.1062, 
     884.1085,904.4734,872.4323,749.6835,736.6229,773.6344,816.7553,858.8569,853.3249,891.7048, 
     850.5705,754.4007,354.7462,343.2167,337.7637,330.5004,309.0369,318.4770,335.2704,346.9049, 
     422.9287,385.5191,410.3909,416.1298,423.8248,353.9624,264.2674,199.2254,342.5222,319.3892, 
     325.5104,293.2321,289.0946,294.4882,307.3506,295.4908,344.1240,326.8981,326.8264,356.7491, 
     362.6374,459.3103,431.8374,436.6566,433.1298,430.9657,419.5703,494.0244,370.0444,439.8624, 
     296.8736,546.3018,311.0276,330.3982,346.5127,292.0111,392.9396,336.4151,310.8202) 

F2 <- c (1708.907,1703.188,1763.067,1757.835,1768.614,1651.012,1550.874,1593.289,1641.620,1238.515,1674.767, 
     1679.122,1638.291,1213.908,1793.527,1948.038,1782.379,1665.103,1646.012,1412.545,1746.250,1924.981, 
     2715.633,2593.596,2657.560,2609.197,2553.094,2712.059,2688.420,2668.596,2574.913,2576.952,2615.174, 
     2570.738,2520.431,2635.001,2726.716,2491.044,2638.541,2741.096,2708.415,2661.317,2725.348,2684.339, 
     2644.370,2724.902,2574.692,1092.502,1154.349,1698.169,1753.618,1138.324,1200.801,1592.622,1788.171, 
     1668.637,1442.751,1587.081,1871.528,1783.440,1429.906,1606.038,1318.925,1623.297,1452.331,1822.482, 
     1972.793,2017.814,1291.637) 

register<-c("ADS","ADS","ADS","ADS","ADS","ADS","ClearSpeech","ClearSpeech","ClearSpeech","ClearSpeech","ClearSpeech","ClearSpeech","ClearSpeech","IDS","IDS","IDS","IDS","IDS","IDS","IDS","IDS","IDS","ADS","ADS","ADS","ADS","ADS","ADS","ADS","ClearSpeech","ClearSpeech","ClearSpeech","ClearSpeech","ClearSpeech","ClearSpeech","ClearSpeech","IDS","IDS","IDS","IDS","IDS","IDS","IDS","IDS","IDS","IDS","IDS","ADS","ADS","ADS","ADS","ClearSpeech","ClearSpeech","ClearSpeech","ClearSpeech","ClearSpeech","ClearSpeech","ClearSpeech","ClearSpeech","ClearSpeech","IDS","IDS","IDS","IDS","IDS","IDS","IDS","IDS","IDS") 
syllable <- c ("a2", "a2", "a2", "a2", "a2", "a2", "a2", "a2", "a2", "a2", "a2", "a2", "a2", "a2", "a2", "a2", "a2", "a2", "a2", "a2", "a2", "a2", "i2", "i2", "i2", "i2", "i2", "i2", "i2", "i2", "i2", "i2", "i2", "i2", "i2", "i2", "i2", "i2", "i2", "i2", "i2", "i2", "i2", "i2", "i2", "i2", "i2", "u2", "u2", "u2", "u2", "u2", "u2", "u2", "u2", "u2", "u2", "u2", "u2", "u2", "u2", "u2", "u2", "u2", "u2", "u2", "u2", "u2", "u2") 

data <- data.frame(syllable, register, F1, F2) 

# calculate mean values using the dplyr package  
mean_values <- data %>% group_by(register, syllable) %>% summarise_each(funs(mean)) 

p <- ggplot() + 
    geom_point(aes(x = F1, y = F2, shape = syllable, color = register), data = data) + 
    geom_point(aes(x = F1, y = F2, shape = syllable, color = register), size = 3, data = mean_values) + 
    geom_polygon(aes(x = F1, y = F2, group = register, color = register), fill = NA, data = mean_values) 

enter image description here

+0

ありがとう!しかし、 "%>%"は特定のパッケージをインストールする必要がありますか?それは言った:エラー:関数 "%>%"を見つけることができませんでした –

+0

私はすべての必要なパッケージをロードしました。すべての依存関係でインストールしてください。 – Alex

+0

ありがとう!すばらしいです! –