Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Explore top 5 names

  • Loading branch information...
commit 67dd8fa1d001faf630fb36cafd2c89c17adb8da1 1 parent 36544b3
@hadley authored
Showing with 19 additions and 0 deletions.
  1. +19 −0 7-top5.r
View
19 7-top5.r
@@ -0,0 +1,19 @@
+bnames <- read.csv("baby-names.csv")
+
+library(plyr)
+# add ranks
+ranked <- ddply(bnames, .(sex, year), transform, rank = rank(-percent))
+
+top5 <- subset(ranked, rank <= 5)
+top5$name <- as.character(top5$name)
+
+library(ggplot2)
+qplot(year, reorder(name, year, min), data = top5, group = name, geom = "text", label = rank) + facet_wrap(~ sex, scales = "free_y")
+
+qplot(year, reorder(name, year, min), data = top5, group = name, colour = rank) + facet_wrap(~ sex, scales = "free_y")
+
+
+qplot(year, percent, data = top5, group = name, colour = rank) +
+ facet_wrap(~ name) +
+ scale_x_continuous(breaks = c(1880, 1920, 1960, 2000))
+
Please sign in to comment.
Something went wrong with that request. Please try again.