The following generates 3 arrays from some data frames.
Ga = data.matrix(GDP_per_capita_FINALE)
Ia = data.matrix(Internet_usage_finale)
Ma = data.matrix(Mobile_cellular_subscriptions_per_100_people_)
w_GDP = Ga[6,][2:21]
w_internet = Ia[6,][2:21]
w_mobile = Ma[6,][2:21]
print(w_GDP)
returns [1] 8169.163 8222.646 8296.169 8435.812 8698.593 8927.916 9204.324 9484.938 9542.370 9269.275 9553.185 9738.992 9867.455 10012.005 10178.372 10349.993 10497.649 10721.484 10920.123 11059.488
and it's about the same for the other two lists
I want to plot a correlation plot between the 3 lists, it should be, and I am expecting, a 3x3
matrix consisting of cor(c(w_mobile), c(w_GDP))=0.9657749
, cor(c(w_internet), c(w_GDP))=0.9837412
, cor(c(w_mobile), c(w_internet))=0.9751028
, and the correlation of 1 between each list with themselves.
What I tried is to make the matrix mat = matrix(c(w_GDP, w_mobile, w_internet), nrow=3)
then perform
temp = cor(mat)
ggcorrplot(temp,
hc.order = TRUE,
type = "lower",
lab = TRUE)
But this returns the 20x20
plot
Which is not what I am looking for, I need the 3x3
plot involving the variables I mentioned above ( cor(c(w_mobile), c(w_GDP))
, and the rest), Anyone know what I should do?
I think the matrix should be created columnwise meaning w_GDP
should be column 1 and so on. An easy way would be to just put the vectors in a dataframe. Try:
dat = data.frame(w_GDP, w_internet,w_mobile)
temp = cor(dat)
ggcorrplot::ggcorrplot(temp, hc.order = TRUE, type = "lower", lab = TRUE)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.