Skip to content

Instantly share code, notes, and snippets.

@andresAlvarado
Created November 9, 2016 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save andresAlvarado/931bb9d2e3cad5b77515dd9661cf89e9 to your computer and use it in GitHub Desktop.
Save andresAlvarado/931bb9d2e3cad5b77515dd9661cf89e9 to your computer and use it in GitHub Desktop.
library('ggplot2')
# Dataset column names and classes
l_colnames = c( 'game_no','stadium', 'team', 'x_cord', 'y_cord', 'desc' )
l_colClasses = c( 'numeric', 'character', 'character', 'numeric', 'numeric', 'character' )
# Load the dataset
hip_data <- read.csv( file = 'hitsPerGame.csv'
, header = F
, col.names = l_colnames
, colClasses = l_colClasses
, na.strings = ''
, stringsAsFactors = T
)
# Create plot
( ggplot()
+ geom_point( data = hip_data
, aes( x = x_cord
, y = y_cord
, color = desc
)
, size = 1.2
)
+ facet_wrap( ~stadium )
+ coord_equal()
+ labs( x = 'X'
, y = 'Y'
, title = 'Batted Balls in Play - WS 2016'
)
+ theme( panel.grid = element_blank()
, strip.background = element_rect( fill = '#5d6c93' )
, strip.text = element_text( color = 'white' )
, axis.text = element_text( size = 8 )
, axis.title = element_text( size = 8 )
, plot.title = element_text( size = 11 )
, legend.title = element_text( size = 10 )
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment