bar_chart {ggcharts} | R Documentation |
Bar Chart
Description
Easily create a bar chart
Usage
bar_chart(
data,
x,
y,
facet = NULL,
...,
bar_color = "auto",
highlight = NULL,
sort = TRUE,
horizontal = TRUE,
top_n = NULL,
threshold = NULL,
other = FALSE,
limit = NULL
)
column_chart(
data,
x,
y,
facet = NULL,
...,
bar_color = "auto",
highlight = NULL,
sort = NULL,
horizontal = FALSE,
top_n = NULL,
threshold = NULL,
limit = NULL
)
Arguments
data |
Dataset to use for the bar chart |
x |
|
y |
|
facet |
|
... |
Additional arguments passed to |
bar_color |
|
highlight |
|
sort |
|
horizontal |
|
top_n |
|
threshold |
|
other |
|
limit |
Deprecated. use |
Details
Both top_n
and threshold
only work when sort = TRUE
.
Attempting to use them when sort = FALSE
will result in an error.
Furthermore, only top_n
or threshold
can be used at a time.
Providing a value for both top_n
and threshold
will result in
an error as well.
column_chart()
is a shortcut for bar_chart()
with
horizontal = FALSE
and sort = FALSE
if x
is
numeric
.
Value
An object of class ggplot
Author(s)
Thomas Neitmann
See Also
For more details have a look at these vignettes:
vignette("highlight", package = "ggcharts")
vignette("customize", package = "ggcharts")
Examples
data(biomedicalrevenue)
revenue2018 <- biomedicalrevenue[biomedicalrevenue$year == 2018, ]
revenue_roche <- biomedicalrevenue[biomedicalrevenue$company == "Roche", ]
## By default bar_chart() creates a horizontal and sorted plot
bar_chart(revenue2018, company, revenue)
## If the `y` argument is missing the count of each value in `x` is displayed
bar_chart(mtcars, cyl)
## Create a vertical, non-sorted bar chart
bar_chart(revenue_roche, year, revenue, horizontal = FALSE, sort = FALSE)
## column_chart() is a shortcut for the above
column_chart(revenue_roche, year, revenue)
## Limit the number of bars to the top 10
bar_chart(revenue2018, company, revenue, top_n = 10)
## Display only companies with revenue > 40B.
bar_chart(revenue2018, company, revenue, threshold = 40)
## Change the bar color
bar_chart(revenue2018, company, revenue, bar_color = "purple")
## Highlight a single bar
bar_chart(revenue2018, company, revenue, top_n = 10, highlight = "Roche")
## Use facets to show the top 10 companies over the years
bar_chart(biomedicalrevenue, company, revenue, facet = year, top_n = 10)