生信可视化

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

2020-07-23  本文已影响0人  小明的数据分析笔记本
数据来源

https://covid19.who.int/?gclid=Cj0KCQjwpNr4BRDYARIsAADIx9zEF_2Pdrovr0jrIsAsMFxUVJLQwfErKz6VcHwR6G8bBx1W1QJSz0waAqAEEALw_wcB

代码

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万"))

结果

image.png

欢迎大家关注我的公众号
小明的数据分析笔记本

公众号二维码.jpg
上一篇 下一篇

猜你喜欢

热点阅读