Skip to content

Instantly share code, notes, and snippets.

@so-c
Last active December 29, 2016 03:48
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 so-c/8007552 to your computer and use it in GitHub Desktop.
Save so-c/8007552 to your computer and use it in GitHub Desktop.
読んだ本の年ごとの積み上げ棒グラフ
library("tidyverse")
raw.entries <- data.frame(年=factor(c(2012, 2013, 2014, 2015, 2016)),
小説=c(69, 65, 71, 65, 90),
読書=c(34, 48, 24, 30, 21),
新書=c(3, 2, 9, 5, 4),
漫画=c(17, 44, 67, 80, 97))
entries <- raw.entries %>% gather(ラベル, 冊数, -年)
g <- ggplot(entries, aes(x=年, y=冊数, fill=ラベル))
p <- g + geom_bar(stat="identity")
p <- p + ggtitle("読んだ本")
plot(p)
ggsave(file="books2015.png", plot=p, width=8.0, height=6.4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment