ryurko / fcscrapR

R package to scrape soccer commentary and statistics from ESPN
28 stars 11 forks source link

small bug in the code #3

Closed iamrafael8 closed 6 years ago

iamrafael8 commented 6 years ago

image

The number of colors shall be 5 instead of 4 in the example code

library(ggplot2) srb_crc_commentary %>% dplyr::filter(!is.na(shot_result)) %>% ggplot(aes(x = shot_by_team, fill = shot_result)) + geom_bar() + labs(x = "Team", y = "Count", fill = "Shot result", title = "Distribution of shot attempts for Costa Rica vs Serbia by result", caption = "Data from ESPN, accessed with fcscrapR") + scale_fill_manual(values = c("darkorange", "darkblue", "darkred", "darkcyan")) + theme_bw()

ryurko commented 6 years ago

I'm not encountering the same error as you. This code example above was meant for the Serbia vs Costa Rica match, did you change the game id? Because other games could have own-goals which would be another type for shot_result causing it to be 5 instead of 4.

iamrafael8 commented 6 years ago

Yes exactly, I have usedd Uruguay vs Russia which is not working because of the own goals

ryurko commented 6 years ago

Okay, then this isn't an issue with fcscrapR itself (unless the own goals are missing, which has been pointed out in another issue). Instead this is more of how to use ggplot and setting your color scale, with the ow_goal you now now 5 types of shot_result so you need to add another color to the vector inside scale_fill_manual() or use a different version scalefill such as scale_fillbrewer(palette = "Set1") for example. Here's more info: http://www.cookbook-r.com/Graphs/Colors(ggplot2)/