2017-11-23 7 views
0

で視覚化するいくつかの項目間の相関行列を作成するコードがあり、これを最良の方法で視覚化したいのですが、私はcorrplot関数を使用しようとしましたが、 、そこから任意のものを理解し、これは私のデータのサンプルと私のコードです:複雑な相関行列をR

library(corrplot) 
Orders<- structure(list(WHWorkOrderHeaderId = c(137413L, 137413L, 137413L, 
137413L, 137413L, 137413L, 137413L, 137413L, 137413L, 137413L, 
137413L, 137413L, 137429L, 137429L, 137429L, 137429L, 137429L, 
137429L, 137429L, 137429L, 137429L, 137260L, 137260L, 137260L, 
137260L, 137260L, 137260L, 137260L, 137260L, 137260L, 137260L, 
136729L, 136729L, 136729L, 136729L, 136729L, 136729L, 136729L, 
136729L, 136729L, 136729L, 136729L, 136729L, 136729L, 137902L, 
137902L, 137902L, 137902L, 137902L, 137902L, 137902L, 137974L, 
137974L, 138837L, 138837L, 138837L, 138837L, 138837L, 138837L, 
139424L, 139424L, 139424L, 139424L, 139424L, 139424L, 139424L, 
139424L, 139424L, 139642L, 139642L, 139642L, 139642L, 139642L, 
139642L, 139642L, 140676L, 140676L, 140676L, 140676L, 140676L, 
140676L, 140938L, 140938L, 140938L, 140938L, 140938L, 140938L, 
140938L, 140938L, 140938L, 140938L, 141302L, 141302L, 141302L, 
141302L, 141302L, 141302L, 138297L, 138297L, 138297L), OtherLangDescription = structure(c(17L, 
16L, 34L, 19L, 25L, 32L, 18L, 35L, 15L, 27L, 13L, 22L, 16L, 26L, 
5L, 20L, 19L, 14L, 29L, 35L, 27L, 17L, 16L, 30L, 26L, 5L, 19L, 
14L, 31L, 29L, 27L, 23L, 24L, 16L, 30L, 8L, 19L, 14L, 32L, 9L, 
31L, 35L, 27L, 21L, 24L, 30L, 26L, 5L, 14L, 32L, 31L, 26L, 5L, 
11L, 24L, 31L, 15L, 27L, 13L, 11L, 17L, 24L, 10L, 19L, 32L, 6L, 
31L, 33L, 23L, 11L, 17L, 4L, 10L, 19L, 31L, 23L, 11L, 4L, 10L, 
19L, 31L, 11L, 17L, 16L, 14L, 25L, 12L, 31L, 7L, 1L, 2L, 23L, 
3L, 35L, 15L, 27L, 28L, 17L, 24L, 16L), .Label = c(" Green Beans", 
"Baladi Cabbage", "Baladi Garlic", "Banati Grape", "Barshomi Figs", 
"Black Eggplant", "Cantaloupe", "Capsicum", "Carrot", "Chili Pepper", 
"Classic Eggplant", "Cooking Potato", "Coriander", "Cucumber", 
"Dill", "Flame Grape", "frying Potato", "Golden Onion", "Green pepper", 
"Hot Pepper", "Local Celery ", "Local Eggplant", "Local Lemon", 
"Local Pear", "Molokhia", "Momtaza Owais Mango", "Parsley", "Red Globe Grape", 
"Red Onion", "Superior Grape", "Tomato", "White Eggplant ", "Zaghlol Dates", 
"Zebdaya Mango", "Zucchini"), class = "factor")), .Names = c("WHWorkOrderHeaderId", 
"OtherLangDescription"), row.names = c(NA, -100L), class = "data.frame") 

Orders$OtherLangDescription <- as.factor(Orders$OtherLangDescription) 
orderList <- unique(Orders$OtherLangDescription) 
ListId <- lapply(orderList, function(x) subset(Orders, OtherLangDescription == x)$WHWorkOrderHeaderId) 
Initial_Tab <- lapply(ListId, function(x) subset(Orders, WHWorkOrderHeaderId %in% x)$OtherLangDescription) 
Correlation_Tab <- mapply(function(Product, ID) table(Product)/length(ID), 
          Initial_Tab, ListId) 
colnames(Correlation_Tab) <- orderList 
cor_per<- round(Correlation_Tab*100,2) 
#View(cor_per) 
#plot cor matrix 
corrplot(Correlation_Tab, tl.pos="lt", type="upper",   
     tl.col="black", tl.cex=0.6, tl.srt=45, is.corr = FALSE, 
     addCoef.col="black", addCoefasPercent = TRUE, 
     sig.level=0.50, insig = "blank") 
+0

あなたは 'corrplot'パッケージをロードしましたか?あなたの問題は何ですか? – Alex

+0

@Alexはい私は – Believer

+0

でしたコードを再現可能にするためにあなたの質問に追加します。あなたの問題が何であり、何を達成したいのかを述べてください。 – Alex

答えて

0

あなたはネットワークanalyisを使用して試みることができます。これは「http://www.r-graph-gallery.com」の例です。

これはサンプルコードです:

あなたはあなたにこの例を適応させることができますので、あなたがより良い相関を見ることができる:これが結果になり

# library 
library(igraph) 

# data 
head(mtcars) 

# Make a correlation matrix: 
mat=cor(t(mtcars[,c(1,3:6)])) 
# Keep only high correlations 
mat[mat<0.995]=0 

# Make an Igraph object from this matrix: 
network=graph_from_adjacency_matrix(mat, weighted=T, mode="undirected", diag=F) 

plot(network) 

enter image description here