gg_shading_bar {plothelper} | R Documentation |
Drawing Barplot with Shading Colors
Description
In ordinary barplot, each bar has only one color.
This function aims to draw a barplot whose bars
have shading effect. Note: unlike
ggplot2::geom_bar
, this function can only
deals with a vector of frequencies.
Usage
gg_shading_bar(
v,
labels = NULL,
raster = NULL,
flip = FALSE,
change_order = "normal",
equal_scale = FALSE,
smooth = 15,
interpolate = TRUE,
width = 0.8,
color = NA,
linetype = 1,
size = 1,
modify_raster = TRUE,
space = "rgb",
...
)
Arguments
v |
a vector of item frequencies. Negative values are OK. |
labels |
a vector of item names.
Its length should be equal to that of |
raster |
a list. The length of the list
should be equal to that of |
flip |
default is FALSE and the bars
are vertical. When it is TRUE, the bars are
horizontal. Note: when using this function,
DO NOT USE
|
change_order |
when it is "normal" (default),
the drawing order is the order of |
equal_scale |
default is FALSE. When it is TRUE, a bar will use a certain part of the shading colors according to a global scale. See examples. |
smooth |
default is 15. The number of shading colors each bar has. The bigger, the better. |
interpolate |
when it is TRUE (default), it makes the colors smoother. |
width |
the width of each bar. It should be between 0 and 1. |
color |
color of the outlines of the bars. |
linetype |
line type of the outlines of the bars. |
size |
line width of the outlines of the bars. |
modify_raster |
if it is TRUE (default), colors
will be smoothed using the value of |
space |
the |
... |
additional arguments used by
|
Examples
library(ggplot2)
x=c(10, 30, 25, 6)
lab=c("children", "youth", "middle", "aged")
r=list(c("cyan", "red"), c("blue", "yellow"),
c("green", "orange"), c("grey", "black"))
#
## (1) change_order
# change_order = "ordinary", the default
p1=gg_shading_bar(v=x, labels=lab)
# change_order = "big"
p2=gg_shading_bar(v=x, labels=lab, change_order="big")
# flip and let the largest on the top
p3=gg_shading_bar(v=x, labels=lab,
change_order="small", flip=TRUE)
#
## (2) how to use argument raster
p1=gg_shading_bar(v=x, labels=lab, raster=r)
p2=gg_shading_bar(v=x, labels=lab, raster=c("green","red"))
#
## (3) how to use argument equal_scale
# equal_scale = FALSE
# the far side of each bar is red
gg_shading_bar(c(3, 5), raster=c("green", "red"))
# equal_scale = TRUE
# the far side of the shorter bar
# is not red. Rather, it is something
#' between red and green
gg_shading_bar(c(3, 5), raster=c("green", "red"),
equal_scale=TRUE)