威少爷的投篮命中率

资深篮球评论员苏群老师的公众号今天分享的文章是《威少投篮惨不忍睹,但他把MVP给乔治》,其中用表格形式展示了威少爷11年职业生涯出手距离投篮命中率和出手距离所占比重的变化,个人认为这类数据用折线图看起来更为直观,本文记录整理苏群老师文章中用到的数据后使用ggplot2制作折线图的代码

数据整理

不同出手距离的命中率

不同出手距离比重

绘图

1、 出手距离与命中率

library(ggplot2)  library(reshape2)  df1<-read.table("clipboard",header=T)  colnames(df1)<-c("Season","0~1","1~3","3~5","5~7","7~")  mydata1<-melt(df1,id.vars = "Season",variable.name = "shooting_distance",value.name = "Percentage")  ggplot(mydata1,aes(x=Season,y=Percentage,group=shooting_distance,color=shooting_distance))+    geom_line()+scale_color_brewer(name="Shooting Distance(m)",palette="Set1")+    geom_point()+theme_bw()+labs(x="")+    scale_y_continuous(breaks = seq(0,1000,by=100),labels=seq(0,100,by=10),                       limits = c(0,1000))+    theme(legend.key=element_blank(),          legend.background = element_blank(),          axis.text.x = element_text(angle=90,vjust=0.5))

从上图可以看出1-5米内出手命中率近两个赛季明显下降,1米内出手命中率生涯最佳

2、出手距离比例

df2<-read.table("clipboard",header=T)  df2  mydata2<-melt(df2,id.vars = "Season",variable.name = "shooting_distance",value.name = "Proportion")  mydata2$shooting_distance<-factor(mydata2$shooting_distance,levels=c("E","D","C","B","A"))  ggplot(mydata2,aes(x=Season,y=Proportion,fill=shooting_distance))+    geom_bar(stat="identity")+theme_bw()+    scale_fill_brewer(name="Shooting Distance(m)",palette="Set1",                      breaks=c("E","D","C","B","A"),                      labels=c("7~","5~7","3~5","1~3","~1"))+    scale_y_continuous(breaks = seq(0,1000,by=100),labels=seq(0,10,by=1),                       limits = c(0,1000))+    theme(axis.title = element_blank(),          axis.text.x = element_text(angle=90,vjust=0.5))

由上图可以看出,威少本赛季较上个赛季的进攻方式的变化:略微增加了三分球,减少了长两分,其他没有明显变化

参考文献

  • R语言ggplot2包画折线图
  • Legends(ggplot2)
  • ggplot2 legend : Easy steps to change the position and the appearance of a graph legend in R software