I recently had an occasion while working on a three variable interaction plot for a paper where I wanted to remove the leading 0’s in the x-axis text labels using ggplot2. This was primarily due to some space concerns I had for the x-axis labels. Unfortunately, I did not find an obvious way to do this in my first go around. After tickering a bit, I’ve found a workaround. The process is walked through below.
I often see graphs that are poorly implemented in that they do not achieve their goal. One such type of graph that I see are dodged bar charts. Here is an example of a dodged bar chart summarizing the number of all star players by team (focusing specifically on the AL central division) and year from the Lahman r package:
library(Lahman) library(dplyr) library(ggplot2) library(RColorBrewer) AllstarFull$selected <- 1 numAS <- AllstarFull %>% filter(yearID > 2006, lgID == 'AL', teamID %in% c('MIN', 'CLE', 'DET', 'CHA', 'KCA')) %>% group_by(teamID, yearID) %>% summarise(number = sum(selected)) b <- ggplot(numAS, aes(x = teamID, y = number, fill = factor(yearID))) + theme_bw() b + geom_bar(stat = "identity", position = "dodge") + scale_fill_brewer("Year", palette = "Dark2") Note: If you are curious from the above graph, there appears to be two typos in the teamIDs, where CHA should be CHW (Chicago White Sox) and KCA should be KCR (Kansas City Royals).
Here is the code used to create the blog logo. Took a bit of trial and error, especially with the official R logo.
### Creating words with connected points. capE <- data.frame(x = c(1.5,1,1,1.25,1,1,1.5), y = c(3,3,2,2,2,1,1)) capE$time <- 1:nrow(capE) letd <- data.frame(x = c(2, 1.75, 1.65, 1.75, 2, 2), y = c(2,2,1.5,1,1,2.5)) letd$time <- 1:nrow(letd) letu <- data.frame(x = c(2.2, 2.2, 2.35, 2.55, 2.55, 2.55), y = c(2,1.15,1,1.15,2,1)) letu$time <- 1:nrow(letu) letc <- data.