Skip to content

Instantly share code, notes, and snippets.

@cpsievert
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cpsievert/2fd6b1409d844f00c9ce to your computer and use it in GitHub Desktop.
Save cpsievert/2fd6b1409d844f00c9ce to your computer and use it in GitHub Desktop.
library(pitchRx)
library(colorspace)
vals <- rainbow_hcl(361)
data(pitches)
pitches$spin_dir <- with(pitches, factor(round(spin_dir), levels = seq(0, 360)))
p1 <- strikeFX(pitches, color = "spin_dir", point.alpha = 0.3,
adjust = TRUE, contour = TRUE) + facet_grid(pitch_type ~ stand) +
theme(legend.position = "none") +
scale_colour_manual(values = vals) + coord_equal()
df <- data.frame(
variable = factor(vals, levels = unique(vals)),
value = rep(1, 361)
)
p2 <- ggplot(df, aes(x = "", y = value, fill = variable)) +
geom_bar(width = 1, stat = "identity") +
scale_fill_manual(values = vals) +
coord_polar("y") + theme(legend.position = "none") +
ylab("Spin direction legend") + xlab("")
library(gridExtra)
grid.arrange(p1, p2, nrow = 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment