Advertisement
Guest User

Untitled

a guest
May 25th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. plot_season <- function(x, binwidth=10) {
  2. require('burnr')
  3. require('ggplot2')
  4. stopifnot(is.fhx(x))
  5. message('plot_season(): This function is experimental and will likely change in the future.')
  6. x_events <- subset(x, grepl('_fs|_fi', rec_type))
  7. p <- ggplot2::ggplot(x_events, aes(year, fill = rec_type))
  8. p <- (p + ggplot2::geom_histogram(binwidth = binwidth)
  9. brks.major <- NA
  10. brks.minor <- NA
  11. yr_range <- diff(range(x_events$year))
  12. if (yr_range < 100) {
  13. brks.major = seq(round(min(x_events$year), -1),
  14. round(max(x_events$year), -1),
  15. 10)
  16. brks.minor = seq(round(min(x_events$year), -1),
  17. round(max(x_events$year), -1),
  18. 5)
  19. } else if (yr_range >= 100) {
  20. brks.major = seq(round(min(x_events$year), -2),
  21. round(max(x_events$year), -2),
  22. 100)
  23. brks.minor = seq(round(min(x_events$year), -2),
  24. round(max(x_events$year), -2),
  25. 50)
  26. }
  27. p <- (p + ggplot2::scale_x_continuous(breaks = brks.major, minor_breaks = brks.minor)
  28. + ggplot2::theme_bw()
  29. + ggplot2::theme(axis.title.x = ggplot2::element_blank(),
  30. legend.title = ggplot2::element_blank(),
  31. legend.position = "bottom"))
  32. p
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement