Description Usage Arguments Examples
View source: R/geom_shading_bar.R
This function is similar to
geom_bar(aes(x, y), stat="identity")
except that it draws bars with shading colors.
Unlike gg_shading_bar
which
is a convenient function, this function
is used as a ggplot layer.
Accepted properties are different from those
in geom_multi_raster
and
gg_shading_bar
.
(1) x
. It is the same as that in
geom_bar
.
(2) y
. It is the same as that in
geom_bar
.
(3) raster
. It should be
a list with 1 or more character vectors of
colors. If the list only has 1 vector,
all the bars will use the same shading pattern.
If you
have, for example, 5 bars to draw, then you
have to put 5 vectors of colors into a list.
If you use a data frame, it must be a
data frame made by package tibble, and
the column for raster
should be
a list.
(4) width
. It is the same
as that in geom_bar
.
(5) flip
. The default is FALSE.
You only need to use TRUE when you
use coord_flip
. Use outside the
aes(...)
function.
(6) modify_raster
. If
it is TRUE (default), colors
will be smoothed using the value of smooth
.
If raster
has enough colors, you can set
this to FALSE. It is the same as that in
gg_shading_bar
.
(7) equal_scale
. The
default is FALSE. When it is
TRUE, a bar will use a certain part of the shading
colors according to a global scale. It is the same
as that in gg_shading_bar
.
(8) smooth
. The
default is 15. The number of
shading colors each bar has. The bigger, the better.
It is the same as that in gg_shading_bar
.
(9) space
. The color space that is
used. It can be "rgb" (default) or "Lab".
(10) orientation
. This parameter
mimics the same parameter used in
geom_bar
, though acts differently.
This enables to flip the x axis and y axis without
using coord_flip
. If it is NA or "x" (default),
it supposes x = SOME LABELS and y = SOME VALUES.
If it is "y", you must set x = SOME VALUES and
y = SOME LABELS. These effects are the same as
geom_bar
.
NOTE: the function does interpolation as default, so
you does not need to
use interpolate
parameter.
And, unlike gg_shading_bar
, this function
does not draw lines around rectangles.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
mapping |
aes mapping. |
data |
data. It should be a tbl object. |
stat |
stat. |
position |
position. The parameter will not be used here. |
na.rm |
logical, whether to remove NA values. |
show.legend |
This will not be used because the layer does not create any legend. |
inherit.aes |
logical, whether to inherit aes from ggplot(). |
width |
see description. |
flip |
see description. |
modify_raster |
see description
or |
smooth |
see description. |
equal_scale |
see description
or |
space |
see description. |
orientation |
see description. |
... |
additional parameters. |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | # Example 1: use vectors.
x=c("b", "a", "c", "d", "e")
y=c(2, 1, 3, 5, 4)
raster=list(c("blue", "red"), c("green", "orange"),
c("cyan", "yellow"), c("purple", "orangered"), c("grey", "red"))
ggplot()+
geom_shading_bar(aes(x=x, y=y, raster=raster), smooth=40)
#
# Example 2: other parameters
x=1: 5
y=c(1, 2, -3, 5, 4)
raster=list(c("blue", "red"))
ggplot()+
geom_shading_bar(aes(x=x, y=y, raster=raster),
smooth=50, width=0.6, equal_scale=TRUE)+
scale_x_continuous(breaks=1: 5, labels=letters[1: 5])
|
Loading required package: ggplot2
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.