Creates a ggplot2 streamgraph based on ggstream::geom_stream() using the specified period as time
resolution.
Arguments
- data
RDB referendum data as returned by
rfrnds(). A data frame that at minimum contains the column specified inperiodor the columndate(to compute the period column), plus the one(s) specified viaby(if any).- by
datacolumn to group by before counting number of referendums.- period
Type of period to count referendums by. One of
"week","month","quarter","year","decade"or"century".- stacking
Stacking type. One of
"mirror"to stack absolute values symmetrically around the zero line on the x-axis."ridge"to stack absolute values from the zero line on the x-axis upwards."proportional"to stack relative values that add up to 100 %.
- bandwidth
Kernel density estimation bandwidth. A numeric scalar.
- y_lim
Optional Y axis range limit. Only relevant if
stackingis one of"mirror"or"ridge". The limit applies to the upper side ifstacking = "ridge"and to both sides ifstacking = "mirror". A numeric scalar equal or greater than zero.- color_palette
Color palette function that when called with a single integer argument returns that many color codes.
- prune_legend
Whether or not to drop
byfactor levels which don't occur indatafrom the legend. Only has an effect ifbyis of type factor.
Value
A ggplot2 object.
See also
Other visualization functions:
plot_rfrnd_share_per_period(),
plot_topic_segmentation(),
plot_topic_share_per_period()
Examples
data_rdb <- rdb::rfrnds(quiet = TRUE)
rdb::ggplot_streamgraph(data = data_rdb,
by = topics_tier_1,
period = "year")
# you can specify a different color palette
rdb::ggplot_streamgraph(data = data_rdb,
by = topics_tier_1,
period = "year",
color_palette = viridisLite::viridis)
# by default, only factor levels which occur in data are included in the legend
data_rdb |>
dplyr::filter(country_code == "AT") |>
rdb::ggplot_streamgraph(by = topics_tier_1,
period = "decade")
# but you can include *all* factor levels in the legend if you want to
data_rdb |>
dplyr::filter(country_code == "AT") |>
rdb::ggplot_streamgraph(by = topics_tier_1,
period = "decade",
prune_legend = FALSE)