Create Chicklet (Rounded Segmented Column) Charts https://cinc.rud.is/web/packages/ggchicklet/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
4.4 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. % Generated by roxygen2: do not edit by hand
  2. % Please edit documentation in R/geom-chicklet.R
  3. \docType{data}
  4. \name{geom_chicklet}
  5. \alias{geom_chicklet}
  6. \alias{GeomChicklet}
  7. \title{Chicklet (rounded segmented column) charts}
  8. \format{An object of class \code{GeomChicklet} (inherits from \code{GeomRrect}, \code{Geom}, \code{ggproto}, \code{gg}) of length 7.}
  9. \usage{
  10. geom_chicklet(
  11. mapping = NULL,
  12. data = NULL,
  13. position = ggplot2::position_stack(reverse = TRUE),
  14. radius = grid::unit(3, "pt"),
  15. ...,
  16. width = NULL,
  17. na.rm = FALSE,
  18. show.legend = NA,
  19. inherit.aes = TRUE
  20. )
  21. GeomChicklet
  22. }
  23. \arguments{
  24. \item{mapping}{Set of aesthetic mappings created by \code{\link[ggplot2:aes]{aes()}} or
  25. \code{\link[ggplot2:aes_]{aes_()}}. If specified and \code{inherit.aes = TRUE} (the
  26. default), it is combined with the default mapping at the top level of the
  27. plot. You must supply \code{mapping} if there is no plot mapping.}
  28. \item{data}{The data to be displayed in this layer. There are three
  29. options:
  30. If \code{NULL}, the default, the data is inherited from the plot
  31. data as specified in the call to \code{\link[ggplot2:ggplot]{ggplot()}}.
  32. A \code{data.frame}, or other object, will override the plot
  33. data. All objects will be fortified to produce a data frame. See
  34. \code{\link[ggplot2:fortify]{fortify()}} for which variables will be created.
  35. A \code{function} will be called with a single argument,
  36. the plot data. The return value must be a \code{data.frame}, and
  37. will be used as the layer data. A \code{function} can be created
  38. from a \code{formula} (e.g. \code{~ head(.x, 10)}).}
  39. \item{position}{Position adjustment, either as a string, or the result of
  40. a call to a position adjustment function.}
  41. \item{radius}{corner radius (default 3pt)}
  42. \item{...}{Other arguments passed on to \code{\link[ggplot2:layer]{layer()}}. These are
  43. often aesthetics, used to set an aesthetic to a fixed value, like
  44. \code{colour = "red"} or \code{size = 3}. They may also be parameters
  45. to the paired geom/stat.}
  46. \item{width}{Bar width. By default, set to 90\% of the resolution of the data.}
  47. \item{na.rm}{If \code{FALSE}, the default, missing values are removed with
  48. a warning. If \code{TRUE}, missing values are silently removed.}
  49. \item{show.legend}{logical. Should this layer be included in the legends?
  50. \code{NA}, the default, includes if any aesthetics are mapped.
  51. \code{FALSE} never includes, and \code{TRUE} always includes.
  52. It can also be a named logical vector to finely select the aesthetics to
  53. display.}
  54. \item{inherit.aes}{If \code{FALSE}, overrides the default aesthetics,
  55. rather than combining with them. This is most useful for helper functions
  56. that define both data and aesthetics and shouldn't inherit behaviour from
  57. the default plot specification, e.g. \code{\link[ggplot2:borders]{borders()}}.}
  58. }
  59. \description{
  60. This geom behaves much like \code{\link[ggplot2:geom_col]{ggplot2::geom_col()}} but provides the option to
  61. set a corner radius to turn sharp-edged bars into rounded rectangles; it also
  62. sets some sane defaults for making chicklet charts.
  63. }
  64. \details{
  65. \if{html}{
  66. A sample of the output from \code{geom_chicklet()}:
  67. \figure{README-nyt-1.png}{options: width="100\%" alt="Figure: README-nyt-1.png"}
  68. }
  69. \if{latex}{
  70. A sample of the output from \code{geom_chicklet()}:
  71. \figure{README-nyt-1.png}{options: width=10cm}
  72. }
  73. }
  74. \note{
  75. the chicklet/segment stack positions are default set to be reversed (i.e.
  76. left-to-right/bottom-to-top == earliest to latest order).
  77. }
  78. \section{Aesthetics}{
  79. \code{geom_chicklet()} understands the following aesthetics:
  80. \itemize{
  81. \item \code{x}
  82. \item \code{y}
  83. \item \code{alpha}
  84. \item \code{colour}
  85. \item \code{fill}
  86. \item \code{group}
  87. \item \code{linetype}
  88. \item \code{size}
  89. }
  90. Use both \code{fill} and \code{group} when you want a fill colour per-segment but
  91. want to order the segments by another column (as in the Examples).
  92. }
  93. \examples{
  94. library(ggplot2)
  95. data("debates2019")
  96. # set the speaker order
  97. spkr_ordr <- aggregate(elapsed ~ speaker, data = debates2019, sum)
  98. spkr_ordr <- spkr_ordr[order(spkr_ordr[["elapsed"]]),]
  99. debates2019$speaker <- factor(debates2019$speaker, spkr_ordr$speaker)
  100. ggplot(debates2019) +
  101. # use 'group' to control left-to-right order
  102. geom_chicklet(aes(speaker, elapsed, group = timestamp, fill = topic)) +
  103. scale_y_continuous(expand = c(0, 0.01), position = "right") +
  104. coord_flip() +
  105. labs(x = NULL, y = "Minutes Spoken", fill = NULL) +
  106. theme_minimal() +
  107. theme(panel.grid.major.y = element_blank()) +
  108. theme(legend.position = "bottom")
  109. }
  110. \keyword{datasets}