-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.Rhistory
225 lines (225 loc) · 6.39 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
install.packages('echarts4r')
library(tidyverse)
library(rio)
library(echarts4r)
library(tidyverse)
library(rio)
library(echarts4r)
df_li<-read.xlsx("data/WPP2024_POP_F01_1_POPULATION_SINGLE_AGE_BOTH_SEXES.xlsx",sheet=1)
library(openxlsx)
df_li<-read.xlsx("data/WPP2024_POP_F01_1_POPULATION_SINGLE_AGE_BOTH_SEXES.xlsx",sheet=1)
names(df_li)<-df_li[10,]
df_li<-df_li[-(1:10),]
View(df_li)
df_li <-df_li %>% clean_names()
library(janitor)
View(df_li)
View(df_li)
df_li <-df_li %>% clean_names()
View(df_li)
getByCountry<-function(df_li,area){
df_li %>%
select(year,region_subregion_country_or_area==area,x0:x100) %>%
mutate(across(starts_with('x'),~round(as.numeric(.x))))
}
getByCountry<-function(area){
df_li %>%
select(year,region_subregion_country_or_area==area,x0:x100) %>%
mutate(across(starts_with('x'),~round(as.numeric(.x))))
}
df_china<-getByCountry('China')
names(df_li)
getByCountry<-function(area){
df_li %>%
filter(region_subregion_country_or_area==area) %>%
select(year,region_subregion_country_or_area,x0:x100) %>%
mutate(across(starts_with('x'),~round(as.numeric(.x))))
}
df_china<-getByCountry('China')
View(df_china)
e_chart(df_china,year) %>%
e_line(x0)
e_chart(df_china,year) %>%
e_line(x0,name = 'x0') %>%
e_line(x1,name = 'x1') %>%
e_line(x2,name = 'x2') %>%
e_line(x3,name = 'x3') %>%
e_line(x4,name = 'x4') %>%
e_tooltip()
e_chart(df_china,year) %>%
e_line(x0,name = 'x0') %>%
e_line(x1,name = 'x1') %>%
e_line(x2,name = 'x2') %>%
e_line(x3,name = 'x3') %>%
e_line(x4,name = 'x4') %>%
e_line(x25,name = 'x25') %>%
e_line(x26,name = 'x26') %>%
e_line(x27,name = 'x27') %>%
e_line(x28,name = 'x28') %>%
e_line(x29,name = 'x29') %>%
e_line(x30,name = 'x30') %>%
e_tooltip(trigger = 'axis')
library(shiny)
library(bslib)
e_chart(df_china,year) %>%
e_line(x0,name = 'x0') %>%
e_line(x1,name = 'x1') %>%
e_line(x2,name = 'x2') %>%
e_line(x3,name = 'x3') %>%
e_line(x4,name = 'x4') %>%
e_line(x25,name = 'x25') %>%
e_line(x26,name = 'x26') %>%
e_line(x27,name = 'x27') %>%
e_line(x28,name = 'x28') %>%
e_line(x29,name = 'x29') %>%
e_line(x30,name = 'x30') %>%
e_tooltip(trigger = 'axis') %>%
e_datazoom()
runApp('code.R')
export(df_li,'data.df_li.rds')
#df_li<-read.xlsx("data/WPP2024_POP_F01_1_POPULATION_SINGLE_AGE_BOTH_SEXES.xlsx",sheet=1)
export(df_li,'data/df_li.rds')
#df_li<-read.xlsx("data/WPP2024_POP_F01_1_POPULATION_SINGLE_AGE_BOTH_SEXES.xlsx",sheet=1)
#export(df_li,'data/df_li.rds')
df_li<-import('data/df_li.rds')
runApp('code.R')
runApp('code.R')
View(df_li)
View(df_li)
runApp('code.R')
library(tidyverse)
library(rio)
library(echarts4r)
library(openxlsx)
library(janitor)
library(shiny)
library(bslib)
#df_li<-read.xlsx("data/WPP2024_POP_F01_1_POPULATION_SINGLE_AGE_BOTH_SEXES.xlsx",sheet=1)
# names(df_li)<-df_li[10,]
# df_li<-df_li[-(1:10),]
#df_li <-df_li %>% clean_names()
#export(df_li,'data/df_li.rds')
df_li<-import('data/df_li.rds')
# df_pop_un_2019<-df_li %>%
# filter(year==2019,type=='Country/Area') %>%
# select(year,region_subregion_country_or_area,type,x0,x1,x2,x3,x4,x5) %>%
# mutate(across(starts_with('x'),~round(as.numeric(.x))))
getByCountry<-function(area){
df_li %>%
filter(region_subregion_country_or_area==area) %>%
select(year,region_subregion_country_or_area,x0:x100) %>%
mutate(across(starts_with('x'),~round(as.numeric(.x))))
}
df_china<-getByCountry('China')
names(df_li)
e<-e_chart(df_china,year) %>%
e_line(x0,name = 'x0') %>%
e_line(x1,name = 'x1') %>%
e_line(x2,name = 'x2') %>%
e_line(x3,name = 'x3') %>%
e_line(x4,name = 'x4') %>%
e_line(x25,name = 'x25') %>%
e_line(x26,name = 'x26') %>%
e_line(x27,name = 'x27') %>%
e_line(x28,name = 'x28') %>%
e_line(x29,name = 'x29') %>%
e_line(x30,name = 'x30') %>%
e_tooltip(trigger = 'axis') %>%
e_datazoom()
e
library(shiny); runApp('code.R')
runApp('code.R')
shiny::runApp()
shiny::runApp()
runApp('code.R')
library(tidyverse)
library(rio)
library(echarts4r)
library(openxlsx)
library(janitor)
library(shiny)
library(bslib)
# df_pre_2023<-read.xlsx("data/WPP2024_POP_F01_1_POPULATION_SINGLE_AGE_BOTH_SEXES.xlsx",sheet=1)
# df_pos_2023<-read.xlsx("data/WPP2024_POP_F01_1_POPULATION_SINGLE_AGE_BOTH_SEXES.xlsx",sheet=2)
#
# names(df_pre_2023)<-df_pre_2023[10,]
# df_pre_2023<-df_pre_2023[-(1:10),] %>% clean_names()
#
# names(df_pos_2023)<-df_pos_2023[10,]
# df_pos_2023<-df_pos_2023[-(1:10),] %>% clean_names()
#
# df_pop<-bind_rows(pre_2023=df_pre_2023,pos_2023=df_pos_2023,.id = 'from') %>%
# mutate(year=as.integer(year))
#
# export(df_pop,'data/df_pop.rds')
df_pop<-import('data/df_pop.rds')
# df_pop_un_2019<-df_pop %>%
# filter(year==2019,type=='Country/Area') %>%
# select(year,region_subregion_country_or_area,type,x0,x1,x2,x3,x4,x5) %>%
# mutate(across(starts_with('x'),~round(as.numeric(.x))))
getByCountry<-function(area){
df_pop %>%
filter(region_subregion_country_or_area==area) %>%
select(year,region_subregion_country_or_area,x0:x100) %>%
mutate(across(starts_with('x'),~round(as.numeric(.x))))
}
df_china<-getByCountry('China')
names(df_pop)
e<-e_chart(df_china,year) %>%
e_line(x0,name = 'x0') %>%
e_line(x1,name = 'x1') %>%
e_line(x2,name = 'x2') %>%
e_line(x3,name = 'x3') %>%
e_line(x4,name = 'x4') %>%
e_line(x16,name = 'x16') %>%
e_line(x17,name = 'x17') %>%
e_line(x18,name = 'x18') %>%
e_line(x25,name = 'x25') %>%
e_line(x26,name = 'x26') %>%
e_line(x27,name = 'x27') %>%
e_line(x28,name = 'x28') %>%
e_line(x29,name = 'x29') %>%
e_line(x30,name = 'x30') %>%
e_tooltip(trigger = 'axis') %>%
e_datazoom()
df_china %>%
pivot_longer(cols = c(4:6),names_to = 'age',values_to = 'pop') %>%
group_by(age) %>%
e_chart(year) |>
e_line(pop) |>
e_tooltip(trigger = 'axis') |>
e_datazoom(type = "inside") |>
e_datazoom(type = "slider") |>
e_x_axis(type='category') |>
e_mark_line(
data = list(
xAxis = 2023
)
)
df_china[,-2] %>%
pivot_longer(cols = -1,names_to = 'age') %>%
pivot_wider(id_cols = age,names_from = year,names_prefix = 'y')
df_china %>%
select(year,starts_with("x")) %>%
pivot_longer(cols = -year,
names_to = "age",
values_to = "population") %>%
mutate(
age = as.numeric(gsub("x", "", age)),
male = -population/2, # 假设男女各半
female = population/2
) %>%
arrange(desc(age)) %>%
na.omit() %>%
group_by(year) %>%
e_charts(age,timeline =T) %>%
e_bar(male, name = "男性", barWidth = "90%", barGap = "-100%") %>%
e_bar(female, name = "女性", barWidth = "90%") %>%
e_flip_coords()
export(df_pop,'data/df_pop.xlsx')
export(df_pop,'data/df_pop.csv')
export(df_pop,'data/df_pop.json')
dir('data')
dir()
dir('data')
git rm --cached data/WPP2024_POP_F01_1_POPULATION_SINGLE_AGE_BOTH_SEXES.xlsx