2017-11-23 3 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

이것은 결과 일 것이다 :

은 예제 코드입니다.