(The datasets I use to create my plots, and the code to scrape the data from Wikipedia using Python, can be found here: https://github.com/davidraxen/wikiscraping/ )
First I read my dataset using the read.delim() function.
players <- read.delim("Chelsea_players.csv", header=TRUE, sep=",", fill = TRUE)
Then I sum up all premier league starts and substitutions for each name using the aggregate() function with sum in a new dataframe called players2. - And renames the column with the sums to "plApps".
players2 <- aggregate(players$PremierLeagueApps+players$PremierLeagueSubs, by=list(Name=players$Name), FUN=sum)
names(players2)[2] <- "plApps"
Then I'm filtering out all players with less than 100 games for chelsea and make a default dotchart.
players2 <- players2[which(players2$plApps > 99),]
dotchart(players2$plApps, labels = players2$Name, cex = .5) #The cex-argument is used to determine character-size.
To make it a bit easier to gather information in we can make it prettier! What and how explained with comments!
players2 = players2[order(players2$plApps),] # First we order the dataframe (and thus the plot) by number of apps.
dotchart(players2$plApps, labels = players2$Name, # What to plot
pch=19, col = "blue1", # pch sets the markers as a filled circle col sets the colors for the markers,
lcolor = "gray90", cex=0.5, # lcolor sets the color for the lines Inside the plot and cex sets the character size.
main = "No. Premier League games for Chelsea per player", #Sets the title for the plot.
xlab = "No. Games", cex.main = 2, cex.lab = 1.5) #xlab sets the label for the x axis and cex.main & cex.lab sets char size for main resp label.
Let's add some more changes to make it even easier to get information out of!
par(bg = 'grey', bty = "l") # Set the background color as grey and changing the "box" around the plot to an L.
dotchart(players2$plApps, labels = players2$Name,
pch=19, col = c("blue1", "snow"), #The vector in col sets alterning colors for the markers
lcolor = "gray90", cex=0.5,
main = "No. Premier League games for Chelsea per player",
cex.main = 2) #removed the unneccisary xlabel.
mtext("Data source: The wikipedia pages for each Chelsea-season from 00/01 to present.", #adds text to side of the plot
side = 1, line = 3, adj = 1, col = "dodgerblue4", cex = .4) # side 1 means at the bottom (2,3,4 -> L,U,R), #adj sets the distance from the plot
Wow! Such many games JT. And nice to see Mikel finally getting some credit!
Yorumlar