项目作者: hrbrmstr

项目描述 :
🀫 Create Chicklet (Rounded Segmented Column) Charts
高级语言: HTML
项目地址: git://github.com/hrbrmstr/ggchicklet.git
创建时间: 2019-06-29T00:52:26Z
项目社区:https://github.com/hrbrmstr/ggchicklet

开源协议:Other

下载


Project Status: Active – The project has reached a stable, usable
state and is being actively
developed.
Signed
by
Signed commit
%
Linux build
Status
Coverage
Status
Minimal R
Version
License

ggchicklet

Create Chicklet (Rounded Segmented Column) Charts

Description

Sometimes it is useful to stylize column charts a bit more than just
bland rectangles. Methods are provided to create rounded rectangle
segmented column charts (i.e. “chicklets”).

What’s Inside The Tin

  • debates2019: 2019-2020 U.S. Democratic Debate Candidate/Topic
    Times
  • geom_chicklet: Chicklet (rounded segmented column) charts

The following functions are implemented:

Installation

  1. install.packages("ggchicklet", repos = "https://cinc.rud.is")
  2. # or
  3. remotes::install_git("https://git.rud.is/hrbrmstr/ggchicklet.git")
  4. # or
  5. remotes::install_git("https://git.sr.ht/~hrbrmstr/ggchicklet")
  6. # or
  7. remotes::install_gitlab("hrbrmstr/ggchicklet")
  8. # or
  9. remotes::install_bitbucket("hrbrmstr/ggchicklet")
  10. # or
  11. remotes::install_github("hrbrmstr/ggchicklet")

NOTE: To use the ‘remotes’ install options you will need to have the
{remotes} package installed.

Usage

  1. library(ggchicklet)
  2. # current version
  3. packageVersion("ggchicklet")
  4. ## [1] '0.5.2'

From the NYTimes

  1. library(hrbrthemes)
  2. library(tidyverse)
  3. data("debates2019")
  4. debates2019 %>%
  5. filter(debate_group == 1) %>%
  6. mutate(speaker = fct_reorder(speaker, elapsed, sum, .desc=FALSE)) %>%
  7. mutate(topic = fct_other(
  8. topic,
  9. c("Immigration", "Economy", "Climate Change", "Gun Control", "Healthcare", "Foreign Policy"))
  10. ) %>%
  11. ggplot(aes(speaker, elapsed, group = timestamp, fill = topic)) +
  12. geom_chicklet(width = 0.75) +
  13. scale_y_continuous(
  14. expand = c(0, 0.0625),
  15. position = "right",
  16. breaks = seq(0, 14, 2),
  17. labels = c(0, sprintf("%d min.", seq(2, 14, 2)))
  18. ) +
  19. scale_fill_manual(
  20. name = NULL,
  21. values = c(
  22. "Immigration" = "#ae4544",
  23. "Economy" = "#d8cb98",
  24. "Climate Change" = "#a4ad6f",
  25. "Gun Control" = "#cc7c3a",
  26. "Healthcare" = "#436f82",
  27. "Foreign Policy" = "#7c5981",
  28. "Other" = "#cccccc"
  29. ),
  30. breaks = setdiff(unique(debates2019$topic), "Other")
  31. ) +
  32. guides(
  33. fill = guide_legend(nrow = 1)
  34. ) +
  35. coord_flip() +
  36. labs(
  37. x = NULL, y = NULL, fill = NULL,
  38. title = "How Long Each Candidate Spoke",
  39. subtitle = "Nights 1 & 2 of the June 2019 Democratic Debates",
  40. caption = "Each bar segment represents the length of a candidate’s response to a question.\n\nOriginals <https://www.nytimes.com/interactive/2019/admin/100000006581096.embedded.html?>\n<https://www.nytimes.com/interactive/2019/admin/100000006584572.embedded.html?>\nby @nytimes Weiyi Cai, Jason Kao, Jasmine C. Lee, Alicia Parlapiano and Jugal K. Patel\n\n#rstats reproduction by @hrbrmstr"
  41. ) +
  42. theme_ipsum_rc(grid="X") +
  43. theme(axis.text.x = element_text(color = "gray60", size = 10)) +
  44. theme(legend.position = "top")

ggchicklet Metrics

Lang # Files (%) LoC (%) Blank lines (%) # Lines (%)
HTML 12 0.55 10200 0.92 3169 0.97 501 0.71
R 8 0.36 788 0.07 45 0.01 122 0.17
Rmd 2 0.09 117 0.01 45 0.01 85 0.12

Code of Conduct

Please note that this project is released with a Contributor Code of
Conduct
. By participating in this project you agree to
abide by its terms.