User Tools

Site Tools


r:baseball_data

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
r:baseball_data [2017/06/05 08:39] hkimscilr:baseball_data [2017/06/05 11:37] hkimscil
Line 1: Line 1:
 +http://score.sports.media.daum.net/record/baseball/kbo/brnk.daum
 +http://www.koreabaseball.com/Record/Player/HitterBasic/Basic1.aspx
 +
 {{:r:baseball_performance.csv}} {{:r:baseball_performance.csv}}
 {{:r:17.3-1.txt}} {{:r:17.3-1.txt}}
Line 4: Line 7:
  
 setwd("c:\\r_temp") setwd("c:\\r_temp")
- 
 data <- read.csv("baseball_performance.csv", header=T) data <- read.csv("baseball_performance.csv", header=T)
 head(data,25) head(data,25)
-bp <- barplot(data$연봉대비출루율, main=paste("야구 선수별 연봉 대비 출루율 분석"),  +data$forward_rate <- (data$출루율/data$연봉)*100 
-       col=rainbow(25) , + 
-       cex.names=0.7, las=2, names.arg=data$선수명, ylim=c(0,50))+bp <- barplot(data$forward_rate 
 +      main=paste("연봉대비 출루율"),  
 +      col=rainbow(25),  
 +      cex.names=0.7, las=2,  
 +      names.arg=data$선수명,  
 +      ylim=c(0,50))
  
 title(ylab="연봉대비출루율", col.lab="red") title(ylab="연봉대비출루율", col.lab="red")
  
-# the below can be achieved by mean() function 
 aver <- 0 aver <- 0
-for(i in 1:length(data$연봉대비출루율)) +for(i in 1:length(data$forward_rate)) 
-   { +   { aver <- aver+data$forward_rate[i] }
-     aver <- aver+data$연봉대비출루율[i] +
-   } +
-aver +
 aver <- aver/length(data$연봉대비출루율) aver <- aver/length(data$연봉대비출루율)
 aver aver
  
 abline(h=aver, col="blue") abline(h=aver, col="blue")
- 
 text(x=aver-11, y=14.5, col="black", cex=0.8, labels=paste(aver,'%',"(평균출루율)")) text(x=aver-11, y=14.5, col="black", cex=0.8, labels=paste(aver,'%',"(평균출루율)"))
 text(x=bp*1.01, y=data$연봉대비출루율*1.05, col="black", cex=0.7,  text(x=bp*1.01, y=data$연봉대비출루율*1.05, col="black", cex=0.7, 
    labels=paste(data$연봉대비출루율,'%'))    labels=paste(data$연봉대비출루율,'%'))
  
-savePlot("baseball_bar.png",type="png")+dev.copy(png,filename="barplot.png") 
 +dev.off() 
 </code> </code>
  
 {{:r:out_rate.png}} {{:r:out_rate.png}}
  
 +나이팅게일 챠트
 <code> <code>
-# 나이팅게일 챠트로 표현하기 
 data <- read.csv("주요선수별성적-2013년.csv", header=T) data <- read.csv("주요선수별성적-2013년.csv", header=T)
 data data
Line 45: Line 47:
 stars(data2,flip.labels=FALSE, draw.segment=TRUE, frame.plot=TRUE, full=TRUE,  stars(data2,flip.labels=FALSE, draw.segment=TRUE, frame.plot=TRUE, full=TRUE, 
      main=" 야구 선수별 주요 성적 분석-2013년 ")      main=" 야구 선수별 주요 성적 분석-2013년 ")
 +dev.copy(png, filename="baseball_ny.png")
 +dev.off()
  
-savePlot("baseball_ny.png",type="png") 
  
 label <- names(data2) label <- names(data2)
Line 52: Line 55:
 color <- c("black","red","green","blue","cyan","violet","yellow","grey") color <- c("black","red","green","blue","cyan","violet","yellow","grey")
 pie(val,labels=label,col=color, radius=0.1, cex=0.6) # 범례용 그래프 만들기 pie(val,labels=label,col=color, radius=0.1, cex=0.6) # 범례용 그래프 만들기
-savePlot("baseball_regend.png",type="png")+dev.copy(png, filename="baseball_regend.png") 
 +dev.off() 
 +</code>
  
 +{{:r:baseball_ny.png}}
 +{{:r:baseball_regend.png}}
 +
 +<code>
 #연봉대비 출루율과 연봉대비 타점율 표현하기 #연봉대비 출루율과 연봉대비 타점율 표현하기
  
Line 70: Line 79:
 par(new=T)  par(new=T) 
      
-plot(line2,type="o",axes=F, ylab="",xlab="",ylim=c(0,50),lty=2,col="red")+plot(line2,type="o",axes=F, ylab="",xlab="",ylim=c(0,50),lty=2,col="red",lwd=2)
 axis(4,las=1)  axis(4,las=1) 
 mtext(side=4,line=2.5,"연봉대비 타점율" mtext(side=4,line=2.5,"연봉대비 타점율"
Line 79: Line 88:
 legend(18,50,names(data[21:22]),cex=0.8,col=c("red","blue"),lty=1,lwd=2,bg="white") legend(18,50,names(data[21:22]),cex=0.8,col=c("red","blue"),lty=1,lwd=2,bg="white")
  
-savePlot("baseball_4.png",type="png")+</code> 
 +{{:r:baseball_4.png}}
  
- 
- 
-</code> 
r/baseball_data.txt · Last modified: 2019/09/18 08:00 by hkimscil

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki