ggplot2折线图展示美国和印度COVID-19单日新增确诊人数变化趋势

时间:2022-07-22
本文章向大家介绍ggplot2折线图展示美国和印度COVID-19单日新增确诊人数变化趋势,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

数据来源

代码

df<-read.csv("../../WHO-COVID-19-global-data.csv",header=T,
             stringsAsFactors = F)
head(df)
df1<-df[df$Country_code=="US"|df$Country_code=="IN",]
head(df1)
table(df1$Country_code)
table(df1$Country)
library(ggplot2)
df2<-na.omit(df1)
x_labels<-paste("2020-0",1:7,"-11",sep="")
x_labels
ggplot(df2,aes(x=Date_reported,y=New_cases,group=Country_code))+
  geom_point(aes(color=Country_code))+
  geom_line(aes(color=Country_code))+
  scale_x_discrete(breaks=x_labels,
                   labels=x_labels)+
  theme_bw()+
  ggtitle("美国和印度每日新增确诊人数")+
  theme(legend.title = element_blank(),
        legend.position = "top",
        plot.title = element_text(hjust=0.5))+
  labs(x="",y="")+
  scale_color_manual(values=c("red","blue"))+
  scale_y_continuous(breaks=c(0,20000,40000,60000),
                     labels = c("0","2万","4万","6万"))

结果