forked from common2016/FactorandIndustry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.Rhistory
512 lines (512 loc) · 24.2 KB
/
.Rhistory
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
PicData$PosNeg <- as.factor(PicData$PosNeg)
# 避免部分异常值太大或太小,从而图形大小比例失衡而进行的截尾处理
PicData[PicData$poten_y_rate > quantile(PicData$poten_y_rate,0.97,na.rm = T),'poten_y_rate'] <- 0.4
PicData <- PicData[abs(PicData$poten_y_rate) > 0.05,]
# 绘制图4气泡图
## 定义要素约束、非充分发展、非重要行业
library(reshape2)
leading <- openxlsx::read.xlsx('data-raw/主导产业.xlsx',1) %>% melt(id.vars = 'province')
names(leading)[2:3] <- c('leading','code_name')
leading$leading <- 'LeadingIndus'
PicData <- merge(PicData, leading[,], by = c('province','code_name'),all.x = T)
PicData$IndusCls <- NA
PicData$IndusCls[PicData$PosNeg == 0] <- 'const'
PicData$IndusCls[PicData$PosNeg == 1 & is.na(PicData$leading)] <- 'NotImp'
PicData$IndusCls[is.na(PicData$IndusCls)] <- 'NotSuffi'
## 绘图
p <- ggplot(data = PicData,aes(x=province,y=code_name,size = abs(poten_y_rate),fill=PosNeg,shape = IndusCls)) + geom_point()+
labs(x=NULL,y=NULL) + scale_shape_manual(values = c(23,21,22))
p + scale_size_area(max_size = 10,guide=FALSE)+guides(fill = FALSE,shape = FALSE)+
scale_fill_grey(start = 0.4,end = 0.8) + theme_bw() +
theme(axis.text.x = element_text(angle = 90, size = rel(1.4)),
axis.text.y = element_text(size = rel(1.4)))
Sys.time()
rm(list = ls())
library(tidyverse)
library(ggplot2)
library(randomForest)
devtools::load_all()
ans <- Sys.time()
RltFinal <- Prelnd(FactorEndw,Ind0111,IndCode,CityEmp,CityWage, n = 500)
Sys.time() - ans
PicData <- group_by(Since2009[Since2009$year == 2016 |
Since2009$year == 2015|
Since2009$year == 2014,],province,code_name) %>%
summarise(poten_y_rate_down = mean(poten_y_rate_down),
poten_y_rate_up = mean(poten_y_rate_up),
poten_y_rate = mean(poten_y_rate))
# 只绘显著的
PicData <- PicData[PicData$poten_y_rate_down * PicData$poten_y_rate_up > 0,]
PicData$PosNeg <- 0
PicData$PosNeg[PicData$poten_y_rate < 0] <- 1
PicData$PosNeg <- as.factor(PicData$PosNeg)
# 避免部分异常值太大或太小,从而图形大小比例失衡而进行的截尾处理
PicData[PicData$poten_y_rate > quantile(PicData$poten_y_rate,0.97,na.rm = T),'poten_y_rate'] <- 0.4
PicData <- PicData[abs(PicData$poten_y_rate) > 0.05,]
# 绘制图4气泡图
## 定义要素约束、非充分发展、非重要行业
library(reshape2)
leading <- openxlsx::read.xlsx('data-raw/主导产业.xlsx',1) %>% melt(id.vars = 'province')
names(leading)[2:3] <- c('leading','code_name')
leading$leading <- 'LeadingIndus'
PicData <- merge(PicData, leading[,], by = c('province','code_name'),all.x = T)
PicData$IndusCls <- NA
PicData$IndusCls[PicData$PosNeg == 0] <- 'const'
PicData$IndusCls[PicData$PosNeg == 1 & is.na(PicData$leading)] <- 'NotImp'
PicData$IndusCls[is.na(PicData$IndusCls)] <- 'NotSuffi'
## 绘图
p <- ggplot(data = PicData,aes(x=province,y=code_name,size = abs(poten_y_rate),fill=PosNeg,shape = IndusCls)) + geom_point()+
labs(x=NULL,y=NULL) + scale_shape_manual(values = c(23,21,22))
p + scale_size_area(max_size = 10,guide=FALSE)+guides(fill = FALSE,shape = FALSE)+
scale_fill_grey(start = 0.4,end = 0.8) + theme_bw() +
theme(axis.text.x = element_text(angle = 90, size = rel(1.4)),
axis.text.y = element_text(size = rel(1.4)))
Since2009 <- RltFinal[['RltPredict']]
Since2009 <- bind_rows(Since2009)
PicData <- group_by(Since2009[Since2009$year == 2016 |
Since2009$year == 2015|
Since2009$year == 2014,],province,code_name) %>%
summarise(poten_y_rate_down = mean(poten_y_rate_down),
poten_y_rate_up = mean(poten_y_rate_up),
poten_y_rate = mean(poten_y_rate))
# 只绘显著的
PicData <- PicData[PicData$poten_y_rate_down * PicData$poten_y_rate_up > 0,]
PicData$PosNeg <- 0
PicData$PosNeg[PicData$poten_y_rate < 0] <- 1
PicData$PosNeg <- as.factor(PicData$PosNeg)
# 避免部分异常值太大或太小,从而图形大小比例失衡而进行的截尾处理
PicData[PicData$poten_y_rate > quantile(PicData$poten_y_rate,0.97,na.rm = T),'poten_y_rate'] <- 0.4
PicData <- PicData[abs(PicData$poten_y_rate) > 0.05,]
# 绘制图4气泡图
## 定义要素约束、非充分发展、非重要行业
library(reshape2)
leading <- openxlsx::read.xlsx('data-raw/主导产业.xlsx',1) %>% melt(id.vars = 'province')
names(leading)[2:3] <- c('leading','code_name')
leading$leading <- 'LeadingIndus'
PicData <- merge(PicData, leading[,], by = c('province','code_name'),all.x = T)
PicData$IndusCls <- NA
PicData$IndusCls[PicData$PosNeg == 0] <- 'const'
PicData$IndusCls[PicData$PosNeg == 1 & is.na(PicData$leading)] <- 'NotImp'
PicData$IndusCls[is.na(PicData$IndusCls)] <- 'NotSuffi'
## 绘图
p <- ggplot(data = PicData,aes(x=province,y=code_name,size = abs(poten_y_rate),fill=PosNeg,shape = IndusCls)) + geom_point()+
labs(x=NULL,y=NULL) + scale_shape_manual(values = c(23,21,22))
p + scale_size_area(max_size = 10,guide=FALSE)+guides(fill = FALSE,shape = FALSE)+
scale_fill_grey(start = 0.4,end = 0.8) + theme_bw() +
theme(axis.text.x = element_text(angle = 90, size = rel(1.4)),
axis.text.y = element_text(size = rel(1.4)))
ncol(FactorEndw)
view(FactorEndw)
rm(list = ls())
library(tidyverse)
library(ggplot2)
library(randomForest)
devtools::load_all()
load('data-raw/Since2009_20181107JJYJ.RData')
rm(CityEmp, CityWage, FactorEndw, Ind0111, LstData)
rm(poten_emp, poten_tech,RltFinal)
rm(i,prv)
save.image('data-raw/myrlt.rdata')
source('E:/做过的研究/z_FactorAndIndustry/FollowingEffects/FactorandIndustry/data-raw/main.R', encoding = 'UTF-8', echo=TRUE)
rm(list = ls())
library(tidyverse)
library(ggplot2)
library(randomForest)
devtools::load_all()
# 若设置TRUE, 则在CPU是i9,8核下大约跑22分钟左右。因为是随机抽样,每次跑完结果略有差异。
# 若设置FALSE,则调用以前跑完存储的数据集。
if (FALSE){
ans <- Sys.time()
RltFinal <- Prelnd(FactorEndw,Ind0111,IndCode,CityEmp,CityWage, n = 500)
Sys.time() - ans
Since2009 <- RltFinal[['RltPredict']]
Since2009 <- bind_rows(Since2009)
}else {
load('data-raw/myrlt.RData')
}
rm(PadMissData)
ls()
rm(Prelnd)
save.image('data-raw/myrlt.rdata')
source('E:/做过的研究/z_FactorAndIndustry/FollowingEffects/FactorandIndustry/data-raw/main.R', encoding = 'UTF-8', echo=TRUE)
rm(list = ls())
library(tidyverse)
library(ggplot2)
library(randomForest)
devtools::load_all()
# 若设置TRUE, 则在CPU是i9,8核下大约跑22分钟左右。因为是随机抽样,每次跑完结果略有差异。
# 若设置FALSE,则调用以前跑完存储的数据集。
if (FALSE){
ans <- Sys.time()
RltFinal <- Prelnd(FactorEndw,Ind0111,IndCode,CityEmp,CityWage, n = 500)
Sys.time() - ans
Since2009 <- RltFinal[['RltPredict']]
Since2009 <- bind_rows(Since2009)
}else {
load('data-raw/myrlt.RData')
}
rm(IndCode)
source('E:/做过的研究/z_FactorAndIndustry/FollowingEffects/FactorandIndustry/data-raw/main.R', encoding = 'UTF-8', echo=TRUE)
devtools::load_all()
# 绘偏效应图
# 通用设备
DrawIndus <- 'C34'
PicName <- 'PartialEffect_ou_Ready_TY_JJYJ.emf' %>% paste('.\\RltForPapers\\',.,sep = '')
EndwImptn <- c('CityEmp','LandMining','RD','K')
EndwImptn_CHN <- c('行业就业人员年末数','城市工业用地','研究与试验发展人员全时当量','物质资本存量')
p <- DrawFun(DrawIndus,PicName,EndwImptn,EndwImptn_CHN,RltFinal,T)
load("E:/做过的研究/z_FactorAndIndustry/FollowingEffects/FactorandIndustry/data-raw/Since2009_20181107JJYJ.RData")
save(Since2009, RltFinal, file = 'data-raw/myrlt.rdata')
rm(list = ls())
library(tidyverse)
library(ggplot2)
library(cowplot)
library(randomForest)
devtools::load_all()
# 若设置TRUE, 则在CPU是i9,8核下大约跑22分钟左右。因为是随机抽样,每次跑完结果略有差异。
# 若设置FALSE,则调用以前跑完存储的数据集。
if (FALSE){
ans <- Sys.time()
RltFinal <- Prelnd(FactorEndw,Ind0111,IndCode,CityEmp,CityWage, n = 500)
Sys.time() - ans
Since2009 <- RltFinal[['RltPredict']]
Since2009 <- bind_rows(Since2009)
}else {
load('data-raw/myrlt.RData')
}
# 绘偏效应图
# 通用设备
DrawIndus <- 'C34'
PicName <- 'PartialEffect_ou_Ready_TY_JJYJ.emf' %>% paste('.\\RltForPapers\\',.,sep = '')
EndwImptn <- c('CityEmp','LandMining','RD','K')
EndwImptn_CHN <- c('行业就业人员年末数','城市工业用地','研究与试验发展人员全时当量','物质资本存量')
p <- DrawFun(DrawIndus,PicName,EndwImptn,EndwImptn_CHN,RltFinal,T)
p <- DrawFun(DrawIndus,PicName,EndwImptn,EndwImptn_CHN,RltFinal,FALSE)
# draw arrow et al.
p1 <- p$p1 + geom_segment(x = 2000,xend = 50000,y = 1500, yend = 1100,arrow = arrow(length = unit(0.3,'cm')),
size = 1,color = I('grey55')) +
geom_segment(x = 300000,xend = 250000,y = 2500, yend = 2500,arrow = arrow(length = unit(0.3,'cm')),
size = 1,color = I('grey55')) +
geom_segment(x = 200000,xend = 155000,y = 1600, yend = 1800,arrow = arrow(length = unit(0.3,'cm')),
size = 1,color = I('grey55')) +
annotate('text',x = c(2500,300000,200000),y = c(1580,2400,1500),
label = c('1','2','斜率最大'),size = 6,color = I('grey55')) +
labs(x = 'CE')
p2 <- p$p2 + geom_segment(x = 500,xend = 300,y = 1200, yend = 1200,arrow = arrow(length = unit(0.3,'cm')),
size = 1,color = I('grey55')) +
geom_segment(x = 750,xend = 600,y = 1600, yend = 1600,arrow = arrow(length = unit(0.3,'cm')),
size = 1,color = I('grey55')) +
geom_segment(x = 500,xend = 750,y = 2000, yend = 2000,arrow = arrow(length = unit(0.3,'cm')),
size = 1,color = I('grey55')) +
annotate('text',x = c(550,500,1000),y = c(1200,2100,1600),
label = c('1','2','斜率最大'),size = 6,color = I('grey55')) + labs(x = 'LM')
p3 <- p$p3 + geom_segment(x = 30000,xend = 30000,y = 1500, yend = 1300,arrow = arrow(length = unit(0.3,'cm')),
size = 1,color = I('grey55')) +
geom_segment(x = 350000,xend = 300000,y = 2000, yend = 2000,arrow = arrow(length = unit(0.3,'cm')),
size = 1,color = I('grey55')) +
geom_segment(x = 300000,xend = 260000,y = 1700, yend = 1700,arrow = arrow(length = unit(0.3,'cm')),
size = 1,color = I('grey55')) +
annotate('text',x = c(30000,359000,330000),y = c(1580,2000,1750),
label = c('1','2','斜率最大'),size = 6,color = I('grey55'))
p4 <- p$p4 + geom_segment(x = 5000,xend = 7500,y = 1500, yend = 1350,arrow = arrow(length = unit(0.3,'cm')),
size = 1,color = I('grey55')) +
geom_segment(x = 20000,xend = 28000,y = 1650, yend = 1650,arrow = arrow(length = unit(0.3,'cm')),
size = 1,color = I('grey55')) +
geom_segment(x = 40000,xend = 38000,y = 1760, yend = 1760,arrow = arrow(length = unit(0.3,'cm')),
size = 1,color = I('grey55')) +
annotate('text',x = c(5000,43000,10000),y = c(1530,1750,1650),
label = c('1','2','斜率最大'),size = 6,color = I('grey55'))
plot_grid(p1,p2,p3,p4,ncol = 2)
p
PicName
DrawIndus <- 'C39'
PicName <- 'data-raw/partial_effect1.png'
EndwImptn <- c('CityEmp','LandMining','RD','patent')
EndwImptn_CHN <- c('行业就业人员年末数','城市工业用地','研究与试验发展人员全时当量',
'国内专利申请授权数')
p <- DrawFun(DrawIndus,PicName,EndwImptn,EndwImptn_CHN,RltFinal,FALSE)
p1 <- p$p1 + geom_segment(x = 40000,xend = 40000,y = 3000, yend = 1700,arrow = arrow(length = unit(0.3,'cm')),
size = 1,color = I('grey55')) +
geom_segment(x = 2000000,xend = 2000000,y = 8000, yend = 9000,arrow = arrow(length = unit(0.3,'cm')),
size = 1,color = I('grey55')) +
geom_segment(x = 800000,xend = 650000,y = 6000, yend = 6000,arrow = arrow(length = unit(0.3,'cm')),
size = 1,color = I('grey55')) +
annotate('text',x = c(49000,2000000,1500000),y = c(3500,7500,6000),
label = c('1','2','斜率最大'),size = 6,color = I('grey55')) +
labs(x = 'CE')
p2 <- p$p2 + geom_segment(x = 500,xend = 500,y = 3500, yend = 2600,arrow = arrow(length = unit(0.3,'cm')),
size = 1,color = I('grey55')) +
geom_segment(x = 1250,xend = 1250,y = 4500, yend = 5500,arrow = arrow(length = unit(0.3,'cm')),
size = 1,color = I('grey55')) +
geom_segment(x = 1000,xend = 900,y = 3800, yend = 3800,arrow = arrow(length = unit(0.3,'cm')),
size = 1,color = I('grey55')) +
annotate('text',x = c(500,1200,1200),y = c(3600,4500,3800),
label = c('1','2','斜率最大'),size = 6,color = I('grey55')) + labs(x = 'LM')
p3 <- p$p3 + geom_segment(x = 50000,xend = 50000,y = 3500, yend = 2500,arrow = arrow(length = unit(0.3,'cm')),
size = 1,color = I('grey55')) +
geom_segment(x = 470000,xend = 470000,y = 4800, yend = 5800,arrow = arrow(length = unit(0.3,'cm')),
size = 1,color = I('grey55')) +
geom_segment(x = 350000,xend = 380000,y = 5500, yend = 5500,arrow = arrow(length = unit(0.3,'cm')),
size = 1,color = I('grey55')) +
annotate('text',x = c(52000,470000,250000),y = c(3500,4500,5500),
label = c('1','2','斜率最大'),size = 6,color = I('grey55'))
p4 <- p$p4 + geom_segment(x = 50000,xend = 10000,y = 2500, yend = 2500,arrow = arrow(length = unit(0.3,'cm')),
size = 1,color = I('grey55')) +
geom_segment(x = 200000,xend = 200000,y = 3250, yend = 3550,arrow = arrow(length = unit(0.3,'cm')),
size = 1,color = I('grey55')) +
geom_segment(x = 80000,xend = 110000,y = 3200, yend = 3200,arrow = arrow(length = unit(0.3,'cm')),
size = 1,color = I('grey55')) +
annotate('text',x = c(51000,195000,40000),y = c(2550,3250,3200),
label = c('1','2','斜率最大'),size = 6,color = I('grey55'))
plot_grid(p1,p2,p3,p4,ncol = 2)
rm(list = ls())
library(tidyverse)
library(ggplot2)
library(cowplot)
library(randomForest)
library(signal)
devtools::load_all()
ans <- Sys.time()
RltFinal <- Prelnd(FactorEndw,Ind0111,IndCode,CityEmp,CityWage, n = 500)
Sys.time() - ans
Since2009 <- RltFinal[['RltPredict']]
Since2009 <- bind_rows(Since2009)
DrawIndus <- 'C34'
PicName <- 'data-raw/partial_effect1.png'
EndwImptn <- c('CityEmp','LandMining','RD','K')
EndwImptn_CHN <- c('行业就业人员年末数','城市工业用地','研究与试验发展人员全时当量','物质资本存量')
p <- DrawFun(DrawIndus,PicName,EndwImptn,EndwImptn_CHN,RltFinal,FALSE)
# 绘制箭头等
p1 <- p$p1 + geom_segment(x = 2000,xend = 50000,y = 1500, yend = 1100,arrow = arrow(length = unit(0.3,'cm')),
size = 1,color = I('grey55')) +
geom_segment(x = 300000,xend = 250000,y = 2500, yend = 2500,arrow = arrow(length = unit(0.3,'cm')),
size = 1,color = I('grey55')) +
geom_segment(x = 200000,xend = 155000,y = 1600, yend = 1800,arrow = arrow(length = unit(0.3,'cm')),
size = 1,color = I('grey55')) +
annotate('text',x = c(2500,300000,200000),y = c(1580,2400,1500),
label = c('1','2','斜率最大'),size = 6,color = I('grey55')) +
labs(x = 'CE')
p2 <- p$p2 + geom_segment(x = 500,xend = 300,y = 1200, yend = 1200,arrow = arrow(length = unit(0.3,'cm')),
size = 1,color = I('grey55')) +
geom_segment(x = 750,xend = 600,y = 1600, yend = 1600,arrow = arrow(length = unit(0.3,'cm')),
size = 1,color = I('grey55')) +
geom_segment(x = 500,xend = 750,y = 2000, yend = 2000,arrow = arrow(length = unit(0.3,'cm')),
size = 1,color = I('grey55')) +
annotate('text',x = c(550,500,1000),y = c(1200,2100,1600),
label = c('1','2','斜率最大'),size = 6,color = I('grey55')) + labs(x = 'LM')
p3 <- p$p3 + geom_segment(x = 30000,xend = 30000,y = 1500, yend = 1300,arrow = arrow(length = unit(0.3,'cm')),
size = 1,color = I('grey55')) +
geom_segment(x = 350000,xend = 300000,y = 2000, yend = 2000,arrow = arrow(length = unit(0.3,'cm')),
size = 1,color = I('grey55')) +
geom_segment(x = 300000,xend = 260000,y = 1700, yend = 1700,arrow = arrow(length = unit(0.3,'cm')),
size = 1,color = I('grey55')) +
annotate('text',x = c(30000,359000,330000),y = c(1580,2000,1750),
label = c('1','2','斜率最大'),size = 6,color = I('grey55'))
p4 <- p$p4 + geom_segment(x = 5000,xend = 7500,y = 1500, yend = 1350,arrow = arrow(length = unit(0.3,'cm')),
size = 1,color = I('grey55')) +
geom_segment(x = 20000,xend = 28000,y = 1650, yend = 1650,arrow = arrow(length = unit(0.3,'cm')),
size = 1,color = I('grey55')) +
geom_segment(x = 40000,xend = 38000,y = 1760, yend = 1760,arrow = arrow(length = unit(0.3,'cm')),
size = 1,color = I('grey55')) +
annotate('text',x = c(5000,43000,10000),y = c(1530,1750,1650),
label = c('1','2','斜率最大'),size = 6,color = I('grey55'))
plot_grid(p1,p2,p3,p4,ncol = 2)
pos <- data.frame(x = c(2000, 300000, 200000), xend = c(50000,25000,155000),
y = c(1500, 2500,1600), yend = c(1100, 2500, 1800))
pos <- data.frame(x = c(2000, 300000, 200000), xend = c(50000,25000,155000),
y = c(1500, 2500,1600), yend = c(1100, 2500, 1800),
xtext = c(2500,300000,200000),
ytext = c(1580,2400,1500))
p1 <- p$p1 + geom_segment(x = pos$x[1],xend = pos$xend[1],y = pos$y[1], yend = pos$yend[1],
arrow = arrow(length = unit(0.3,'cm')),
size = 1,color = I('grey55')) +
geom_segment(x = pos$x[2],xend = pos$xend[2],y = pos$y[2], yend = pos$yend[2],
arrow = arrow(length = unit(0.3,'cm')),
size = 1,color = I('grey55')) +
geom_segment(x = pos$x[3],xend = pos$xend[3],y = pos$y[3], yend = pos$yend[3],
arrow = arrow(length = unit(0.3,'cm')),
size = 1,color = I('grey55')) +
annotate('text',x = pos$xtext,y = pos$ytext,
label = c('1','2','斜率最大'),size = 6,color = I('grey55')) +
labs(x = 'CE')
p1
pos <- data.frame(x = c(2000, 300000, 200000), xend = c(50000,250000,155000),
y = c(1500, 2500,1600), yend = c(1100, 2500, 1800),
xtext = c(2500,300000,200000),
ytext = c(1580,2400,1500))
p$p1 + geom_segment(x = pos$x[1],xend = pos$xend[1],y = pos$y[1], yend = pos$yend[1],
arrow = arrow(length = unit(0.3,'cm')),
size = 1,color = I('grey55')) +
geom_segment(x = pos$x[2],xend = pos$xend[2],y = pos$y[2], yend = pos$yend[2],
arrow = arrow(length = unit(0.3,'cm')),
size = 1,color = I('grey55')) +
geom_segment(x = pos$x[3],xend = pos$xend[3],y = pos$y[3], yend = pos$yend[3],
arrow = arrow(length = unit(0.3,'cm')),
size = 1,color = I('grey55')) +
annotate('text',x = pos$xtext,y = pos$ytext,
label = c('1','2','斜率最大'),size = 6,color = I('grey55')) +
labs(x = 'CE')
devtools::load_all()
p1 <- draw_arrow(p, pos)
p1
devtools::load_all()
pos <- data.frame(x = c(500, 750, 500), xend = c(300,600,750),
y = c(1200, 1600,2000), yend = c(1200, 1600, 2000),
xtext = c(550,500,1000),
ytext = c(1200,2100,1600)) # 设定箭头和文本的坐标
draw_arrow(p$p2, pos)
p2 <- draw_arrow(p$p2, pos)
pos <- data.frame(x = c(500, 750, 500), xend = c(300,600,750),
y = c(1200, 1600,2000), yend = c(1200, 1600, 2000),
xtext = c(550,500,1000),
ytext = c(1200,2100,1600)) # 设定箭头和文本的坐标
p2 <- draw_arrow(p$p2, pos)
p2
pos <- data.frame(x = c(30000, 350000, 300000), xend = c(30000,300000,260000),
y = c(1500, 2000,1700), yend = c(1300, 2000, 1700),
xtext = c(30000,359000,330000),
ytext = c(1580,2000,1750)) # 设定箭头和文本的坐标
draw_arrow(p$p3, pos)
draw_arrow(p$p3, pos)
draw_arrow(p$p3, pos)
p3 <- draw_arrow(p$p3, pos)
p3
pos <- data.frame(x = c(5000, 20000, 40000), xend = c(7500,28000,38000),
y = c(1500, 1650,1760), yend = c(1350, 1650, 1760),
xtext = c(5000,43000,10000),
ytext = c(1530,1750,1650)) # 设定箭头和文本的坐标
p4 <- draw_arrow(p$p4, pos)
p4
plot_grid(p1,p2,p3,p4,ncol = 2)
DrawIndus <- 'C39'
PicName <- 'data-raw/partial_effect1.png'
EndwImptn <- c('CityEmp','LandMining','RD','patent')
EndwImptn_CHN <- c('行业就业人员年末数','城市工业用地','研究与试验发展人员全时当量',
'国内专利申请授权数')
p <- DrawFun(DrawIndus,PicName,EndwImptn,EndwImptn_CHN,RltFinal,FALSE)
p_computer <- DrawFun(DrawIndus,PicName,EndwImptn,EndwImptn_CHN,RltFinal,FALSE)
# 绘制箭头
pos <- data.frame(x = c(40000, 2000000, 800000), xend = c(40000,2000000,650000),
y = c(3000, 8000,6000), yend = c(1700, 9000, 6000),
xtext = c(49000,2000000,1500000),
ytext = c(3500,7500,6000)) # 设定箭头和文本的坐标
p1 <- draw_arrow(p_computer, pos)
p1 <- draw_arrow(p_computer, pos)
p1 <- draw_arrow(p_computer$p1, pos)
p1
pos <- data.frame(x = c(500, 1250, 1000), xend = c(500,1250,900),
y = c(3500, 4500,3800), yend = c(2600, 5500, 3800),
xtext = c(500,1200,1200),
ytext = c(3600,4500,3800)) # 设定箭头和文本的坐标
p2 <- draw_arrow(p_computer$p2, pos)
p2
pos <- data.frame(x = c(50000, 470000, 350000), xend = c(50000,470000,380000),
y = c(3500, 4800,5500), yend = c(2500, 5800, 5500),
xtext = c(52000,470000,250000),
ytext = c(3500,4500,5500)) # 设定箭头和文本的坐标
p3 <- draw_arrow(p_computer$p3, pos)
p3
pos <- data.frame(x = c(50000, 200000, 80000), xend = c(10000,200000,110000),
y = c(2500, 3250,3200), yend = c(2500, 3550, 3200),
xtext = c(51000,195000,40000),
ytext = c(2550,3250,3200)) # 设定箭头和文本的坐标
p4 <- draw_arrow(p_computer$p4, pos)
p4
plot_grid(p1,p2,p3,p4,ncol = 2)
RltForest <- RltFinal[['RltForest']]
PicData <- NULL
for (i in 1:length(RltForest)) {
PicData <- data.frame(endow = row.names(importance(RltForest[[i]])),
IncNodePurity = importance(RltForest[[i]])[,1]/sum(importance(RltForest[[i]])[,1]),
industry = names(RltForest)[i]) %>%
rbind(PicData,.)
}
library(randomForest)
for (i in 1:length(RltForest)) {
PicData <- data.frame(endow = row.names(importance(RltForest[[i]])),
IncNodePurity = importance(RltForest[[i]])[,1]/sum(importance(RltForest[[i]])[,1]),
industry = names(RltForest)[i]) %>%
rbind(PicData,.)
}
for (i in 1:length(RltForest)) {
if (is.null(RltForest[[i]])) next
PicData <- data.frame(endow = row.names(importance(RltForest[[i]])),
IncNodePurity = importance(RltForest[[i]])[,1]/sum(importance(RltForest[[i]])[,1]),
industry = names(RltForest)[i]) %>%
rbind(PicData,.)
}
PicData <- merge(PicData,unique(Ind0111[,c('IndCode','industry')]),by.x = 'industry',by.y = 'IndCode',all.x = T)
PicData$endow_abb <- PicData$endow %>% as.character()
PicData <- PicData[!(PicData$endow %in% 'river'),]
PicData$endow_abb[PicData$endow %in% 'CityEmp'] <- 'CE'
PicData$endow_abb[PicData$endow %in% 'CityWage'] <- 'CW'
PicData$endow_abb[PicData$endow %in% 'RDIntensity'] <- 'RDI'
PicData$endow_abb[PicData$endow %in% 'CropArea'] <- 'CrpA'
PicData$endow_abb[PicData$endow %in% 'CyCntr'] <- 'DIF'
PicData$endow_abb[PicData$endow %in% 'TechImp'] <- 'TI'
PicData$endow_abb[PicData$endow %in% 'InputFee'] <- 'IF'
PicData$endow_abb[PicData$endow %in% 'LandMining'] <- 'LM'
# 绘制要素禀赋重要性图
p <- ggplot(PicData,aes(x=endow_abb,y=industry.y,size = IncNodePurity)) +
geom_point(shape=21,fill = 'grey') + labs(x=NULL,y=NULL)
p + scale_size_area(max_size = 15,guide=FALSE)+guides(fill = FALSE) +
scale_fill_grey(start = 0.4,end = 0.8) + theme_bw()+
theme(axis.text.x = element_text(angle = 90, size = rel(1.4)),
axis.text.y = element_text(size = rel(1.4)))
source('E:/做过的研究/z_FactorAndIndustry/FollowingEffects/FactorandIndustry/data-raw/draw_importance.R', encoding = 'UTF-8', echo=TRUE)
source('E:/做过的研究/z_FactorAndIndustry/FollowingEffects/FactorandIndustry/data-raw/draw_importance.R', encoding = 'UTF-8', echo=TRUE)
source('E:/做过的研究/z_FactorAndIndustry/FollowingEffects/FactorandIndustry/data-raw/draw_importance.R', encoding = 'UTF-8', echo=TRUE)
source('E:/做过的研究/z_FactorAndIndustry/FollowingEffects/FactorandIndustry/R/draw_partial_effect.R', encoding = 'UTF-8', echo=TRUE)
source('E:/做过的研究/z_FactorAndIndustry/FollowingEffects/FactorandIndustry/R/draw_partial_effect.R', encoding = 'UTF-8', echo=TRUE)
source('E:/做过的研究/z_FactorAndIndustry/FollowingEffects/FactorandIndustry/R/draw_partial_effect.R', encoding = 'UTF-8', echo=TRUE)
source('E:/做过的研究/z_FactorAndIndustry/FollowingEffects/FactorandIndustry/R/draw_partial_effect.R', encoding = 'UTF-8', echo=TRUE)
# 绘图4,图5偏效应图
rm(list = ls())
library(tidyverse)
library(ggplot2)
library(cowplot)
library(randomForest)
library(signal)
devtools::load_all()
rm(list = ls())
library(tidyverse)
library(ggplot2)
library(cowplot)
library(randomForest)
library(signal)
devtools::load_all()
load('data-raw/myrlt.RData')
source('E:/做过的研究/z_FactorAndIndustry/FollowingEffects/FactorandIndustry/data-raw/main.R', encoding = 'UTF-8', echo=TRUE)
source('E:/做过的研究/z_FactorAndIndustry/FollowingEffects/FactorandIndustry/data-raw/draw_partial_effect.R', encoding = 'UTF-8', echo=TRUE)
source('E:/做过的研究/z_FactorAndIndustry/FollowingEffects/FactorandIndustry/data-raw/draw_importance.R', encoding = 'UTF-8', echo=TRUE)
view(FactorEndw)
data("FactorEndw")
View(FactorEndw)
knitr::opts_chunk$set(echo = TRUE)
data("Ind0111")
knitr::opts_chunk$set(echo = TRUE)
data("Ind0111")
head(Ind0111)
data("Ind0111")
knitr::opts_chunk$set(echo = TRUE)
getwd()
knitr::opts_chunk$set(echo = TRUE, warning = FALSE, message = FALSE)
devtools::load_all()
data("Ind0111")
head(Ind0111)
devtools::load_all()
data("Ind0111")
head(Ind0111)
knitr::opts_chunk$set(echo = TRUE, warning = FALSE, message = FALSE)
devtools::load_all()
data("Ind0111")
head(Ind0111)
# 不分行业
data("FactorEndw")
head(FactorEndw[,1:6])
# 分行业的工资和就业
data("CityEmp")
data("CityWage")
head(CityEmp[,1:5])
head(CityWage[,1:5])
source('E:/CompletedResearch/z_FactorAndIndustry/FollowingEffects/FactorandIndustry/data-raw/draw_importance.R', encoding = 'UTF-8', echo=TRUE)