' R- i5 J; _, \: T1. 中国新增确诊病例变化趋势% Q; K0 o3 [: `9 f$ ~* n #合并所有省份新增确诊人数2 X0 w( [% L F/ I5 o i
china<-new_data[new_data$`Country/Region`=='China',] ' n* f, O5 [: tchina_increase<-data.frame(apply(china[,-c(1:4)],2,sum))0 W8 h/ x# G, Y8 r7 _& n8 N
colnames(china_increase)<-'increase_patient' # \) ~0 G% i9 M* L! p- B5 t, S6 Lchina_increase$date<-as.Date(rownames(china_increase),format="%Y-%m-%d") 9 B" {$ }1 x2 L9 W+ _) i8 S m# D' R* A6 [
ggplot(china_increase,aes(x=date,y=increase_patient,color='新增确诊人数'))+geom_line(size=1)+5 C8 W+ J/ u, [4 p+ g6 C, q
scale_x_date(date_breaks = "14 days")+ #设置横轴日期间隔为14天(注意:此时的date列必须为日期格式!)4 f& O: D y, r; {9 ]! i
labs(x='日期',y='新增确诊人数',title='2020年1月22日-2020年12月7日中国新增确诊人数变化趋势图')+0 s, p3 [5 j/ J _
theme_economist()+ #使用经济学人绘图样(式ggthemes包) 9 b3 r: I' d/ u$ j theme(plot.title = element_text(face="plain",size=15,hjust=0.5),' L/ p) {3 k* W/ _/ E7 S. V
axis.title.x = element_blank(),1 y9 B7 Y3 Z5 F# U5 w
axis.title.y = element_text(size=15), / ^7 Q. e t# d/ h9 \! g axis.text.x = element_text(angle = 90,size=15), $ O9 Z, L8 ]3 p* ? axis.text.y = element_text(size=15), # z3 ^# F$ ]' n legend.title=element_blank(), ( j7 ^ ^" c& Q legend.text=element_text(size=15)) , T/ b$ u4 J$ F4 x. y l K6 D: J) _+ k i4 D0 `2 ]9 M: H" ?8 u
2. 美国新增病例变化趋势6 t4 |# ^+ A/ N6 A( G us<-new_data[new_data$`Country/Region`=='United States',]1 N! X; L6 S1 n- U$ Y
us_increase<-gather(us,key="date",value="increase_patient",'2020-01-22':'2020-12-07'); U4 \( k! \! M; G# i
us_increase$date<-as.Date(us_increase$date) ! t5 u4 G+ j, \6 nggplot(us_increase,aes(x=date,y=increase_patient,color='新增确诊人数'))+geom_line(size=1)+ 0 z1 t/ N ^* i$ G3 r# I! d. V scale_x_date(date_breaks = "14 days")+ #设置横轴日期间隔为14天 / c) k: h& X) K$ s& m: O labs(x='日期',y='新增确诊人数',title='2020年1月22日-2020年12月7日美国新增确诊人数变化趋势图')+ 9 @/ j* a0 b2 N( v$ ^ theme_economist()+ #使用经济学人绘图样(式ggthemes包) 5 R" s/ x+ d3 E. t; p theme(plot.title = element_text(face="plain",size=15,hjust=0.5), 5 @4 M3 L* ~) C$ T7 h$ H6 a& i axis.title.x = element_blank(), - l; b; R" \8 P: y, o. X axis.title.y = element_text(size=15),$ z/ }$ j/ _+ u; ^
axis.text.x = element_text(angle = 90,size=15), 9 q% y% b. V8 j! u& P axis.text.y = element_text(size=15),! N3 J7 K6 N9 E p5 B0 B
legend.title=element_blank(), ! h- A" k. |/ j( ]& U4 j7 ] legend.text=element_text(size=15)) 2 `, U; v. r6 g- N; Y7 ^* U* W2 `& Y6 ~( Z$ I$ X3 N. S 6 O) T2 m7 J4 V! t
3. 全球新增病例变化趋势 5 n3 x" V* a, E- \( E7 Ttotal_increase<-data.frame(apply(new_data[,-c(1:4)],2,sum)) " {6 }% x$ F0 N6 |; @3 g: Icolnames(total_increase)<-'increase_patient' ) u7 b2 T+ v( k Itotal_increase$date<-as.Date(rownames(total_increase),format="%Y-%m-%d")2 Y9 f# L" K( b/ d! M3 g' }$ w8 y
ggplot(total_increase,aes(x=date,y=increase_patient,color='新增确诊人数'))+geom_line(size=1)+ / Z' @: h; M! N scale_x_date(date_breaks = "14 days")+ . }: w" m' X% ^9 h, k' g: u7 R8 S labs(x='日期',y='新增确诊人数',title='2020年1月22日-2020年12月7日全球新增确诊人数变化趋势图')+4 b" [$ N9 N' J
theme_economist()+ - M6 m' l7 p0 E# ~* m0 F! _6 H# k$ D scale_y_continuous(limits=c(0,8*10^5), #考虑数字过大,以文本形式标注y轴标签( y* q9 q; S9 N1 R5 J4 j
breaks=c(0,2*10^5,4*10^5,6*10^5,8*10^5), $ o! b/ a1 |$ k$ q$ K labels=c("0","20万","40万","60万","80万"))+ : G h8 q0 l+ O+ F% x* _ theme(plot.title = element_text(face="plain",size=15,hjust=0.5),# t' L I$ H/ l$ r; u' v0 k: O
axis.title.x = element_blank(), , h' |; x' A) C+ O8 v; I axis.title.y = element_text(size=15), * N! j9 a" X* \" p axis.text.x = element_text(angle = 90,size=15), k" a" q* c w s+ F, C3 c
axis.text.y = element_text(size=15), 4 P5 t( X0 d0 ?% ~ legend.title=element_blank(), ) t$ P+ M. f4 s) p legend.text=element_text(size=15)) 4 O( Y% P- c* V5 m6 l5 y d5 B 0 r8 t) ^; i/ J8 j$ M! _6 w8 Z2 t! z% k' @! \8 a 三、新增确诊病例全球地理分布" W- e& n! F% Q0 X6 E
mapworld<-borders("world",colour = "gray50",fill="white") ' F9 \: X1 S5 z& Q3 t/ I: Z
ggplot()+mapworld+ylim(-60,90)+ ( `# c7 w0 t' I+ C7 m8 ^1 d geom_point(aes(x=new_data$Long,y=new_data$Lat,size=new_data$`2020-01-22`),color="darkorange")+ . C9 s4 b2 w ] scale_size(range=c(2,9))+labs(title="2020年1月22日全球新增确诊人数分布")+ / r7 A; y y5 s theme_grey(base_size = 15)+ / w+ i8 ]# i0 g9 F) f% \ theme(plot.title=element_text(face="plain",size=15,hjust=0.5),! g: U& P. ~, d
legend.title=element_blank())( G8 W; ~4 s( j( Q& }% s: e4 i% t
2 R: N4 A. n vggplot()+mapworld+ylim(-60,90)+ 0 ~7 c# c* e) \ h- D geom_point(aes(x=new_data$Long,y=new_data$Lat,size=new_data$`2020-11-22`),color="darkorange")+ ) b. f& X r1 ?8 ^7 [: U scale_size(range=c(2,9))+labs(title="2020年11月22日全球新增确诊人数分布")+9 E6 l E2 Z9 g9 D) v/ t# T) d
theme_grey(base_size = 15)+: u7 {4 `7 `+ [$ C: J" R/ H& H% d2 M
theme(plot.title=element_text(face="plain",size=15,hjust=0.5)," }$ v. ?7 o6 ~4 @8 H6 c9 M
legend.title=element_blank())2 g. C$ n' [( P3 S
1 B# s p8 Z- V) k* d5 B% ?$ w, C. `/ [* F. k% G 四、累计确诊病例动态变化图