NCOL: how many columns to use in the ggplot2 facet display (default is 1).stat: what batting statistic is used (default is “oWAR”).table: what Baseball-Reference table is accessed (default is “batting_value”, but one can also use “batting_value”).Names: a vector of player names which each name is either a full name “Barry Bonds” or the associated Lahman playerID “bondsba01” (Sometimes we have to use playerID for players like Pete Rose and Ken Griffey Jr.The ease of directly reading Baseball-Reference tables motivated me to write a function comparing_baseball_trajectories.R that will compare trajectories of a group of players using a table and associated batting statistic. Ggplot(filter(standard, Lg="NL"), aes(Age, HR)) + (Have to be careful about the variable type - Age and HR are both factor variables that need to be converted to numeric.) Okay, suppose we wish to plot Bonds’ home run numbers for only his MLB seasons against age. Note that, unlike what you see on the Baseball-Reference page, the first row contains stats forthe first minor league season on Bonds and the last row is his final MLB season (the “Total” rows are removed). We can access the Standard Batting table: Note that the variable d is a list with the following elements: To download this page into R, we use the readHTMLtable function from the XML package. We will focus on the use of the first two tables. “Standard Batting” gives the season to season standard batting statistics, “Player Value” gives a number of modern batting measures, “Postseason Batting” gives batting statistics for each playoff season that Bonds played on, etc. On this Baseball-Reference page there are a number of html tables. shtml This simple structure makes it easy to download this page by the readHTMLTable function. This url is the character string followed by the first letter of the player’s last name followed by a slash and the usual Lahman player id followed by. Look at a Baseball-Reference page for a non-pitcher, say Barry Bonds. In honor of Mike Piazza’s and Ken Griffey’s recent induction in the HOF, we’ll compare their offensive hitting trajectories against similar great catchers and outfielders. In this post, we’ll illustrate the use of the XML package to read in several Baseball-Reference pages and compare career trajectories of historical players using any batting statistic of interest. Moreover, the web pages on this site have a convenient structure that facilitates reading the tables directly into R. For each MLB player in history, it contains much of the Retrosheet data, and it also lists many of the modern batting measures for each season. Baseball-Reference is a great source of baseball data.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |