Description Usage Arguments Value Author(s) Examples
Use this function to create bar chart using with 2 or 3 variables and at least one numeric variable.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | bar_chart(
plot_data,
x_name,
y_name,
color_name = NULL,
static_color = "#4dbd5b",
border_line_color = "#ffffff00",
border_line_width = 2,
stack = FALSE,
sort_asc = FALSE,
highlight = NULL,
plot_height = NULL,
plot_width = NULL,
show_legend = TRUE,
show_x_axis_grid = FALSE,
show_y_axis_grid = FALSE,
sort_colors_alphabetically = FALSE,
plot_title = "",
x_axis_title = NULL,
y_axis_title = NULL
)
|
plot_data |
The data which will be used for the plot |
x_name |
The column name of the variable in the x-axis, It can be a numeric or factor variable |
y_name |
The column name of the variable in the y-axis, It can be a factor or numeric variable |
color_name |
The column name of the variable in the color axis, It has to be a factor variable |
static_color |
string. If the colour_name is not specified, this color will be filled for the plot |
border_line_color |
string. The color of the border line around the bar, default is invisible |
border_line_width |
num. The width of the border line |
stack |
boolean. This will convert your coloured plot to stacked bar instead of grouped bar |
sort_asc |
boolean. This will let you sort the plot ascending, the plot is sorted descending by default |
highlight |
char_vactor. A vector of values from y_name which will be highlighted. Optional, if not provided every y-axis variable will have same color |
plot_height |
num. The height of the plot, If not provided the plot will take the whole area available in the UI |
plot_width |
num. The height of the plot, If not provided the plot will take the whole area available in the UI |
show_legend |
boolean. This will let you display or hide the grids in the x-axis, default shown |
show_x_axis_grid |
boolean. This will let you display or hide the grids in the x-axis, default hidden |
show_y_axis_grid |
boolean. This will let you display or hide the grids in the y-axis, default shown |
sort_colors_alphabetically |
boolean. This will sort the color legends alphabetically |
plot_title |
string. This is the title of the plot, defauts to NULL |
x_axis_title |
string. This is the x-axis title of the plot, defaults to NULL |
y_axis_title |
string. This is the y-axis title of the plot, defaults to NULL |
Returns a plotly plot object which can be rendered as HTML
Vedha Viyash
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | ## Creating a sample data for bar chart without color axis
library(dplyr)
data("tidychartsdata")
plot_data <- marks_data %>% group_by(name) %>% summarise(marks = mean(marks))
## All you need to plot a bar chart is the data, x_name and y_name
bar_chart(plot_data, name, marks)
## You can highlight values from your factor axis by specifying it as highlight parameter .
bar_chart(plot_data, name, marks, highlight = c("Danny", "Jon", "Tyrion"))
## To get a horizontal bar chart all you need to do is to pass the x and y variables accordingly
bar_chart(plot_data, marks, name)
## You can highlight variables by passing highlight and change the color using static_color
bar_chart(
plot_data, marks, name,
highlight = c("Arya", "Bran", "Sansa"), static_color = "#5884d6"
)
## You can pass a factor variable in color_name, this will add a grouped bar chart
bar_chart(marks_data, name, marks, subject)
## To flip the axis all you have to do is to interchange the x and y names
bar_chart(marks_data, marks, name, subject)
## If you'd like to have a stacked bar, just pass stack = TRUE
bar_chart(marks_data, name, marks, subject, stack = TRUE)
## stack = TRUE also works for horizontal grouped bar charts
bar_chart(marks_data, marks, name, subject, stack = TRUE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.