多元数据直观表示

Author

221527114柯金余

Quarto

Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see https://quarto.org.

Running Code

When you click the Render button a document will be generated that includes both content and the output of embedded code. You can embed code like this:

#导入数据

library(openxlsx)
Warning: package 'openxlsx' was built under R version 4.3.3
d3.1=read.xlsx("D:/大三R/chapter 3/mvstats5.xlsx",'d3.1',rowNames=T);d3.1
          食品    衣着   设备    医疗    交通    教育    居住   杂项
北京   4934.05 1512.88 981.13 1294.07 2328.51 2383.96 1246.19 649.66
天津   4249.31 1024.15 760.56 1163.98 1309.94 1639.83 1417.45 463.64
河北   2789.85  975.94 546.75  833.51 1010.51  895.06  917.19 266.16
山西   2600.37 1064.61 477.74  640.22 1027.99 1054.05  991.77 245.07
内蒙古 2824.89 1396.86 561.71  719.13 1123.82 1245.09  941.79 468.17
辽宁   3560.21 1017.65 439.28  879.08 1033.36 1052.94 1047.04 400.16
吉林   2842.68 1127.09 407.35  854.80  873.88  997.75 1062.46 394.29
黑龙江 2633.18 1021.45 355.67  729.55  746.03  938.21  784.51 310.67
上海   6125.45 1330.05 959.49  857.11 3153.72 2653.67 1412.10 763.80
江苏   3928.71  990.03 707.31  689.37 1303.02 1699.26 1020.09 377.37
浙江   4892.58 1406.20 666.02  859.06 2473.40 2158.32 1168.08 467.52
安徽   3384.38  906.47 465.68  554.44  891.38 1169.99  850.24 309.30
福建   4296.22  940.72 645.40  502.41 1606.90 1426.34 1261.18 375.98
江西   3192.61  915.09 587.40  385.91  732.97  973.38  728.76 294.60
山东   3180.64 1238.34 661.03  708.58 1333.63 1191.18 1027.58 325.64
河南   2707.44 1053.13 549.14  626.55  858.33  936.55  795.39 300.19
湖北   3455.98 1046.62 550.16  525.32  903.02 1120.29  856.97 242.82
湖南   3243.88 1017.59 603.18  668.53  986.89 1285.24  869.59 315.82
广东   5056.68  814.57 853.18  752.52 2966.08 1994.86 1444.91 454.09
广西   3398.09  656.69 491.03  542.07  932.87 1050.04  803.04 277.43
海南   3546.67  452.85 519.99  503.78 1401.89  837.83  819.02 210.85
重庆   3674.28 1171.15 706.77  749.51 1118.79 1237.35  968.45 264.01
四川   3580.14  949.74 562.02  511.78 1074.91 1031.81  690.27 291.32
贵州   3122.46  910.30 463.56  354.52  895.04 1035.96  718.65 258.21
云南   3562.33  859.65 280.62  631.70 1034.71  705.51  673.07 174.23
西藏   3836.51  880.10 271.29  272.81  866.33  441.02  628.35 335.66
陕西   3063.69  910.29 513.08  678.38  866.76 1230.74  831.27 332.84
甘肃   2824.42  939.89 505.16  564.25  861.47 1058.66  768.28 353.65
青海   2803.45  898.54 484.71  613.24  785.27  953.87  641.93 331.38
宁夏   2760.74  994.47 480.84  645.98  859.04  863.36  910.68 302.17
新疆   2760.69 1183.69 475.23  598.78  890.30  896.79  736.99 331.80

各消费项目星相图

#没有图例的360度星相图:由下图可知,北京、上海、浙江、广东的星相图面积较大,说明这几个省份发展较好。

stars(d3.1)

#具有图例的360度星相图

可以看出,北京在各个方面的发展最为均衡,上海在医疗以外的其他方面发展的更好。

stars(d3.1,key.loc=c(17,7))

#具有图例的180度星相图

可以看出,上海、北京的发展很不错;广东、浙江的发展较好,但是呈现出不均衡的状况;其他各省份发展较为一般且不均衡。

stars(d3.1,full=F,key.loc=c(17,7)) 

#具有图例的360度彩色圆形星相图

该图比以上各图更为直观,上海、北京的发展很不错;广东、浙江的发展较好,但是呈现出不均衡的状况;其他各省份发展较为一般且不均衡。

stars(d3.1,draw.segments=T,key.loc=c(17,7))

#具有图例的180度彩色圆形星相图

上海、北京的发展很不错;广东、浙江的发展较好,但是呈现出不均衡的状况;其他各省份发展较为一般且不均衡。

stars(d3.1,full=F,draw.segments=T,key.loc=c(17,7))

各消费项目脸谱图

#加载aplpack包

北京、上海、浙江表现得最好。

library(aplpack)
Warning: package 'aplpack' was built under R version 4.3.3
faces(d3.1)

effect of variables:
 modified item       Var   
 "height of face   " "食品"
 "width of face    " "衣着"
 "structure of face" "设备"
 "height of mouth  " "医疗"
 "width of mouth   " "交通"
 "smiling          " "教育"
 "height of eyes   " "居住"
 "width of eyes    " "杂项"
 "height of hair   " "食品"
 "width of hair   "  "衣着"
 "style of hair   "  "设备"
 "height of nose  "  "医疗"
 "width of nose   "  "交通"
 "width of ear    "  "教育"
 "height of ear   "  "居住"

#去掉第一个变量按每行7个做脸谱图

北京、上海、浙江表现得最好;广东也还行。

faces(d3.1[,2:8],ncol.plot=7)

effect of variables:
 modified item       Var   
 "height of face   " "衣着"
 "width of face    " "设备"
 "structure of face" "医疗"
 "height of mouth  " "交通"
 "width of mouth   " "教育"
 "smiling          " "居住"
 "height of eyes   " "杂项"
 "width of eyes    " "衣着"
 "height of hair   " "设备"
 "width of hair   "  "医疗"
 "style of hair   "  "交通"
 "height of nose  "  "教育"
 "width of nose   "  "居住"
 "width of ear    "  "杂项"
 "height of ear   "  "衣着"

#选择第1,9,19,28,29,30个观测的多元数据做脸谱图

下图可以看出我国发达地区与西北地区发展的一些明显的对比,北京、上海、广东的发展状况远好于甘肃、青海、宁夏地区。这说明了我国发展存在不平衡不充分的情况。

faces(d3.1[c(1,9,19,28,29,30),])

effect of variables:
 modified item       Var   
 "height of face   " "食品"
 "width of face    " "衣着"
 "structure of face" "设备"
 "height of mouth  " "医疗"
 "width of mouth   " "交通"
 "smiling          " "教育"
 "height of eyes   " "居住"
 "width of eyes    " "杂项"
 "height of hair   " "食品"
 "width of hair   "  "衣着"
 "style of hair   "  "设备"
 "height of nose  "  "医疗"
 "width of nose   "  "交通"
 "width of ear    "  "教育"
 "height of ear   "  "居住"

#install.packages(“TeachingDemos”)

library("TeachingDemos")
Warning: package 'TeachingDemos' was built under R version 4.3.3

Attaching package: 'TeachingDemos'
The following objects are masked from 'package:aplpack':

    faces, slider
aplpack::faces(d3.1)

effect of variables:
 modified item       Var   
 "height of face   " "食品"
 "width of face    " "衣着"
 "structure of face" "设备"
 "height of mouth  " "医疗"
 "width of mouth   " "交通"
 "smiling          " "教育"
 "height of eyes   " "居住"
 "width of eyes    " "杂项"
 "height of hair   " "食品"
 "width of hair   "  "衣着"
 "style of hair   "  "设备"
 "height of nose  "  "医疗"
 "width of nose   "  "交通"
 "width of ear    "  "教育"
 "height of ear   "  "居住"

各消费项目雷达图

居民在对食品方面的支出占比最大,其次到交通、教育、衣着、居住、医疗设备、其他杂项。

library("fmsb")
Warning: package 'fmsb' was built under R version 4.3.3
rddat=d3.1[c(1,9,19,28,29,30),]
maxmin=rbind(apply(rddat,2,max),apply(rddat,2,min))
rddat=rbind(maxmin,rddat)
radarchart(rddat, axistype=2, pcol=topo.colors(6), plty=1, pdensity=seq(5,40,by=5), pangle=seq(0,150,by=30), pfcol=topo.colors(6))

各消费项目调和曲线图

#加自定义函数

source("D:/大三R/chapter 3/msaR.R")

#绘制调和曲线图

该图可以明显的看出北京发展状况最好。

msa.andrews(d3.1)

下图可以看出我国发达地区与西北地区发展的一些明显的对比,北京、上海、广东的发展状况远好于甘肃、青海、宁夏地区。这说明了我国发展存在不平衡不充分的情况。

msa.andrews(d3.1[c(1,9,19,28,29,30),])