
3 Jul
2015
3 Jul
'15
18:39
Boa tarde, Estou usando a função heatmap para fazer um grafico da correlação entre 30 empresas. Porém a diagonal toda da matriz é 1, e a cor que aparece não é branco para todas elas. Alguém saberia me dizer o por quê disso? Abaixo segue o código. Muito obrigada, Michelle > if (!require("gplots")) { + install.packages("gplots", dependencies = TRUE) + library(gplots) + } > if (!require("RColorBrewer")) { + install.packages("RColorBrewer", dependencies = TRUE) + library(RColorBrewer) + } > library(gplots) > library(RColorBrewer) > > > file<-read.table("/Users/bau/Análise20%/MatrizCorrelaçãoHoraFixaAn20%2Verificação.txt", head=TRUE) > > matriz<-as.matrix(file) > matriz V1 V2 V3 V4 V5 V6 V7 V8 1 1.000000 -0.1488000 -0.120220 -0.278740 0.812920 -0.153150 -0.246640 -0.0706680 2 -0.148800 1.0000000 -0.094092 -0.291490 -0.026490 -0.084461 -0.274460 -0.0053051 3 -0.120220 -0.0940920 1.000000 -0.038117 -0.156290 0.443590 0.555750 -0.0185260 4 -0.278740 -0.2914900 -0.038117 1.000000 -0.186330 -0.316690 -0.233550 -0.1683500 5 0.812920 -0.0264900 -0.156290 -0.186330 1.000000 -0.179180 -0.240810 -0.0821580 6 -0.153150 -0.0844610 0.443590 -0.316690 -0.179180 1.000000 0.314870 -0.0805790 7 -0.246640 -0.2744600 0.555750 -0.233550 -0.240810 0.314870 1.000000 -0.1081200 8 -0.070668 -0.0053051 -0.018526 -0.168350 -0.082158 -0.080579 -0.108120 1.0000000 9 -0.103610 -0.2866200 -0.138530 -0.415740 -0.240890 -0.147270 -0.217480 0.1628300 10 -0.049682 -0.0473140 -0.051863 -0.214470 -0.060698 -0.118840 -0.111480 0.9682600 11 -0.263810 -0.2668200 -0.218920 -0.481630 -0.244870 -0.240020 -0.111070 -0.1727900 12 -0.188570 -0.0335670 0.602170 -0.189760 -0.223400 0.375510 0.474240 -0.1309300 13 -0.241810 -0.1810300 0.313570 -0.352580 -0.243430 0.235260 0.197230 -0.1601100 14 -0.236110 -0.1327000 0.221720 -0.417150 -0.283360 -0.026711 0.061281 0.2914000 15 -0.196730 -0.2440000 -0.180820 -0.472170 -0.120510 -0.266970 -0.263940 0.4074900 16 -0.242250 -0.2702000 -0.176820 -0.406400 -0.234990 -0.210460 0.025799 -0.1415800 17 -0.210830 -0.2452300 -0.194290 -0.340790 -0.188320 -0.318860 -0.244580 -0.0325100 18 -0.205970 -0.2793200 -0.158450 -0.395590 -0.103040 -0.040617 -0.165250 -0.0957780 19 -0.174340 -0.1529100 0.581590 -0.197270 -0.170600 0.362750 0.411190 -0.0440840 20 -0.236400 -0.3040200 -0.259570 -0.432960 -0.277750 -0.257810 -0.498010 -0.2060400 21 0.627290 -0.1816700 -0.148760 -0.334340 0.625360 -0.200010 -0.211250 -0.0982320 22 0.646400 -0.2604900 -0.107130 -0.347920 0.598150 -0.246790 -0.177750 -0.1006800 23 -0.166960 -0.3303900 -0.170460 -0.480110 -0.134900 -0.297750 -0.256080 0.0181360 24 -0.175720 -0.2457900 -0.334160 -0.475940 -0.279300 -0.476930 -0.122630 -0.1589900 25 -0.239010 -0.2516100 -0.261780 -0.358940 -0.243110 -0.330530 -0.418030 -0.0720400 26 -0.072637 -0.1991100 -0.108510 -0.306400 -0.122220 -0.110840 -0.035140 -0.0188130 27 -0.239730 0.0208830 -0.317810 -0.562200 -0.224260 -0.350740 -0.357450 -0.2385000 28 -0.081665 -0.0172600 -0.057269 -0.187130 -0.089078 -0.092451 -0.107760 0.9782200 29 -0.287560 -0.4044900 -0.222730 -0.402910 -0.246270 -0.374840 -0.170290 -0.2050000 30 -0.240640 -0.2494600 -0.161820 -0.363650 -0.301390 -0.335640 -0.221850 -0.0917310 V9 V10 V11 V12 V13 V14 V15 V16 1 -0.103610 -0.049682 -0.2638100 -0.188570 -0.241810 -0.236110 -0.19673 -0.242250 2 -0.286620 -0.047314 -0.2668200 -0.033567 -0.181030 -0.132700 -0.24400 -0.270200 3 -0.138530 -0.051863 -0.2189200 0.602170 0.313570 0.221720 -0.18082 -0.176820 4 -0.415740 -0.214470 -0.4816300 -0.189760 -0.352580 -0.417150 -0.47217 -0.406400 5 -0.240890 -0.060698 -0.2448700 -0.223400 -0.243430 -0.283360 -0.12051 -0.234990 6 -0.147270 -0.118840 -0.2400200 0.375510 0.235260 -0.026711 -0.26697 -0.210460 7 -0.217480 -0.111480 -0.1110700 0.474240 0.197230 0.061281 -0.26394 0.025799 8 0.162830 0.968260 -0.1727900 -0.130930 -0.160110 0.291400 0.40749 -0.141580 9 1.000000 0.111420 -0.3292500 -0.117090 -0.183380 -0.138610 0.10657 -0.297930 10 0.111420 1.000000 -0.1616400 -0.158130 -0.193640 0.249040 0.38221 -0.167030 11 -0.329250 -0.161640 1.0000000 -0.365690 -0.437690 -0.460970 -0.19613 0.173440 12 -0.117090 -0.158130 -0.3656900 1.000000 0.262660 0.152760 -0.28939 -0.286680 13 -0.183380 -0.193640 -0.4376900 0.262660 1.000000 -0.036207 -0.27265 -0.217780 14 -0.138610 0.249040 -0.4609700 0.152760 -0.036207 1.000000 -0.17618 -0.350990 15 0.106570 0.382210 -0.1961300 -0.289390 -0.272650 -0.176180 1.00000 -0.329490 16 -0.297930 -0.167030 0.1734400 -0.286680 -0.217780 -0.350990 -0.32949 1.000000 17 -0.142130 -0.041754 -0.3445100 -0.241300 -0.370250 -0.241910 -0.12044 -0.399280 18 -0.240860 -0.132840 -0.2431700 -0.205090 -0.395380 -0.246830 -0.26935 -0.405670 19 -0.133520 -0.045900 -0.2048300 0.445090 0.349490 0.098674 -0.12891 -0.145070 20 -0.284450 -0.268370 -0.4866800 -0.490160 -0.413300 -0.534260 -0.39506 -0.440230 21 -0.215960 -0.084613 -0.2693500 -0.224280 -0.053839 -0.298130 -0.19650 -0.249920 22 -0.290980 -0.088546 -0.2989100 -0.280310 -0.335690 -0.178300 -0.27805 -0.286220 23 -0.431420 0.024286 -0.3099400 -0.297010 -0.458870 -0.393310 -0.18978 -0.149720 24 -0.461750 -0.174440 -0.2290000 -0.263640 -0.384700 -0.321700 -0.37221 -0.111130 25 -0.277500 -0.117370 -0.3217100 -0.435670 -0.297100 -0.336510 -0.30911 -0.126820 26 0.028362 -0.038184 -0.0044301 -0.051589 -0.238220 -0.292680 -0.20221 0.068210 27 -0.297810 -0.279020 -0.6358500 -0.315320 -0.461570 -0.565570 -0.50525 -0.525960 28 0.138330 0.964190 -0.1637700 -0.135670 -0.175530 0.290640 0.40377 -0.175950 29 -0.377810 -0.226910 -0.0314590 -0.325840 -0.322050 -0.389640 -0.42031 -0.045736 30 -0.274010 -0.103120 -0.4103000 -0.299110 -0.285560 -0.338200 -0.48234 -0.446340 V17 V18 V19 V20 V21 V22 V23 V24 1 -0.210830 -0.205970 -0.174340 -0.23640 0.627290 0.646400 -0.166960 -0.175720 2 -0.245230 -0.279320 -0.152910 -0.30402 -0.181670 -0.260490 -0.330390 -0.245790 3 -0.194290 -0.158450 0.581590 -0.25957 -0.148760 -0.107130 -0.170460 -0.334160 4 -0.340790 -0.395590 -0.197270 -0.43296 -0.334340 -0.347920 -0.480110 -0.475940 5 -0.188320 -0.103040 -0.170600 -0.27775 0.625360 0.598150 -0.134900 -0.279300 6 -0.318860 -0.040617 0.362750 -0.25781 -0.200010 -0.246790 -0.297750 -0.476930 7 -0.244580 -0.165250 0.411190 -0.49801 -0.211250 -0.177750 -0.256080 -0.122630 8 -0.032510 -0.095778 -0.044084 -0.20604 -0.098232 -0.100680 0.018136 -0.158990 9 -0.142130 -0.240860 -0.133520 -0.28445 -0.215960 -0.290980 -0.431420 -0.461750 10 -0.041754 -0.132840 -0.045900 -0.26837 -0.084613 -0.088546 0.024286 -0.174440 11 -0.344510 -0.243170 -0.204830 -0.48668 -0.269350 -0.298910 -0.309940 -0.229000 12 -0.241300 -0.205090 0.445090 -0.49016 -0.224280 -0.280310 -0.297010 -0.263640 13 -0.370250 -0.395380 0.349490 -0.41330 -0.053839 -0.335690 -0.458870 -0.384700 14 -0.241910 -0.246830 0.098674 -0.53426 -0.298130 -0.178300 -0.393310 -0.321700 15 -0.120440 -0.269350 -0.128910 -0.39506 -0.196500 -0.278050 -0.189780 -0.372210 16 -0.399280 -0.405670 -0.145070 -0.44023 -0.249920 -0.286220 -0.149720 -0.111130 17 1.000000 -0.338590 -0.225910 -0.45329 -0.212720 -0.258960 -0.327150 -0.220570 18 -0.338590 1.000000 -0.123500 -0.35347 -0.206230 -0.234200 -0.321910 -0.225490 19 -0.225910 -0.123500 1.000000 -0.30228 -0.180950 -0.237280 -0.269610 -0.332320 20 -0.453290 -0.353470 -0.302280 1.00000 -0.160310 -0.443100 -0.498960 -0.604740 21 -0.212720 -0.206230 -0.180950 -0.16031 1.000000 0.394940 -0.220940 -0.175960 22 -0.258960 -0.234200 -0.237280 -0.44310 0.394940 1.000000 -0.191920 -0.295690 23 -0.327150 -0.321910 -0.269610 -0.49896 -0.220940 -0.191920 1.000000 -0.140490 24 -0.220570 -0.225490 -0.332320 -0.60474 -0.175960 -0.295690 -0.140490 1.000000 25 -0.357960 -0.439870 -0.245740 -0.45062 -0.296380 -0.284950 -0.336660 -0.372750 26 -0.099695 -0.289810 -0.190800 -0.16041 -0.071261 -0.219200 -0.111650 -0.023106 27 -0.516980 -0.148320 -0.330300 -0.57538 -0.288440 -0.420560 -0.667640 -0.552860 28 -0.029953 -0.068158 -0.037025 -0.21447 -0.102620 -0.114390 -0.020426 -0.182240 29 -0.386590 -0.372130 -0.114870 -0.59123 -0.328560 -0.407050 -0.379740 -0.086991 30 -0.296050 -0.491150 -0.252440 -0.20588 -0.176020 -0.156980 -0.549450 -0.447000 V25 V26 V27 V28 V29 V30 1 -0.23901 -0.0726370 -0.239730 -0.081665 -0.287560 -0.240640 2 -0.25161 -0.1991100 0.020883 -0.017260 -0.404490 -0.249460 3 -0.26178 -0.1085100 -0.317810 -0.057269 -0.222730 -0.161820 4 -0.35894 -0.3064000 -0.562200 -0.187130 -0.402910 -0.363650 5 -0.24311 -0.1222200 -0.224260 -0.089078 -0.246270 -0.301390 6 -0.33053 -0.1108400 -0.350740 -0.092451 -0.374840 -0.335640 7 -0.41803 -0.0351400 -0.357450 -0.107760 -0.170290 -0.221850 8 -0.07204 -0.0188130 -0.238500 0.978220 -0.205000 -0.091731 9 -0.27750 0.0283620 -0.297810 0.138330 -0.377810 -0.274010 10 -0.11737 -0.0381840 -0.279020 0.964190 -0.226910 -0.103120 11 -0.32171 -0.0044301 -0.635850 -0.163770 -0.031459 -0.410300 12 -0.43567 -0.0515890 -0.315320 -0.135670 -0.325840 -0.299110 13 -0.29710 -0.2382200 -0.461570 -0.175530 -0.322050 -0.285560 14 -0.33651 -0.2926800 -0.565570 0.290640 -0.389640 -0.338200 15 -0.30911 -0.2022100 -0.505250 0.403770 -0.420310 -0.482340 16 -0.12682 0.0682100 -0.525960 -0.175950 -0.045736 -0.446340 17 -0.35796 -0.0996950 -0.516980 -0.029953 -0.386590 -0.296050 18 -0.43987 -0.2898100 -0.148320 -0.068158 -0.372130 -0.491150 19 -0.24574 -0.1908000 -0.330300 -0.037025 -0.114870 -0.252440 20 -0.45062 -0.1604100 -0.575380 -0.214470 -0.591230 -0.205880 21 -0.29638 -0.0712610 -0.288440 -0.102620 -0.328560 -0.176020 22 -0.28495 -0.2192000 -0.420560 -0.114390 -0.407050 -0.156980 23 -0.33666 -0.1116500 -0.667640 -0.020426 -0.379740 -0.549450 24 -0.37275 -0.0231060 -0.552860 -0.182240 -0.086991 -0.447000 25 1.00000 -0.3001800 -0.582360 -0.103130 -0.591400 -0.361260 26 -0.30018 1.0000000 -0.324240 -0.051578 -0.085934 -0.274650 27 -0.58236 -0.3242400 1.000000 -0.236760 -0.719200 -0.605090 28 -0.10313 -0.0515780 -0.236760 1.000000 -0.215050 -0.104520 29 -0.59140 -0.0859340 -0.719200 -0.215050 1.000000 -0.539620 30 -0.36126 -0.2746500 -0.605090 -0.104520 -0.539620 1.000000 > rownames(matriz)<-c("AA","AIG","AXP","BA","CAT","C","DD","DIS","GE","GM","HD","HON","HPQ","IBM","INTC","JNJ","JPM","KO","MCD","MMM","MO","MRK","MSFT","PFE","PG","SBC","UTX","VZ","WMT","XOM") > colnames(matriz)<-c("AA","AIG","AXP","BA","CAT","C","DD","DIS","GE","GM","HD","HON","HPQ","IBM","INTC","JNJ","JPM","KO","MCD","MMM","MO","MRK","MSFT","PFE","PG","SBC","UTX","VZ","WMT","XOM") > > > my_palette <- colorRampPalette(c( "dark blue", "violet","white"))(n = 299) > png("/Users/bau/Grafico de calor/HeatMapCorrViolet2.jpeg", + width = 5*300, + height = 5*300, + res = 300, + pointsize = 8) > > heatmap(matriz,Rowv=NA,Colv=NA,col=my_palette,scale="column",margins=c(5,10),main="Correlação_HoraFixa_2") > dev.off() [image: Imagem inline 1]