rAmCharts - amBarplot
Parameters
- x: a character, column name for x-axis, or a numeric, number of the corresponding column. It is optional if argument data has row names.
- y: a character, column name for y-axis, or a numeric, number of the corresponding column. If you want to display a grouped barchart or a stacked barchart, y is a vector of characters or numerics.
- data: a dataframe with values to display. You can add a column “color” (character, colors in hexadecimal). You can also add a column “description” (character) containing the text you want to display when mouse is on the graphic (‘<br>’ for a new line).
- groups_color: a character, vector of colors in hexadecimal, same length as y.
- xlab: a character, label for x-axis.
- ylab: a character, label for y-axis.
- horiz: a boolean, TRUE for an horizontal chart, FALSE for a vertical one.
- stack_type: a character, “regular” if you wish stacked bars, “100” if you want 100 percent stacked bars. Default is set to “none”.
- layered: a boolean, TRUE for layered. If TRUE, stack_type must be set to “none”.
- show_values: a boolean, TRUE ti dosplay values.
- depth: a numeric. If depth is superior to 0, chart is displayed in 3D. Value between 0 and 100.
- dataDateFormat: a character, default ‘NULL’. Even if your chart parses dates,you can pass them as strings in your data - all you need to do is to set data date format and the chart will parse dates to date objects. Please note that two-digit years (YY) as well as literal month names (MMM) are NOT supported in this setting.
- minPeriod: a character. Specifies the shortest period of your data. This should be set only if dataDateFormat is not ‘NULL’. Possible period values: fff - milliseconds, ss - seconds, mm - minutes, hh - hours, DD - days, MM - months, YYYY - years. It’s also possible to supply a number for increments, i.e. ‘15mm’ which will instruct the chart that your data is supplied in 15 minutes increments.
- …: other parameters called in amOptions.
Notice: If the chart has many columns, several labels might be hidden. It depends on the width of the conatainer where the chart is displayed. Zoom on the chart to see if the chart can contain all labels. If not, use the parameter labelRotation. You can also add a cursor to your chart…
Data used in the examples:
data("data_bar")
head(data_bar)
## country visits color
## 1 USA 3025 #FF0F00
## 2 China 1882 #FF6600
## 3 Japan 1809 #FF9E01
## 4 Germany 1322 #FCD202
## 5 UK 1122 #F8FF01
## 6 France 1114 #B0DE09
data("data_gbar")
head(data_gbar)
## year day month income expenses
## 1 2005 01/06/2005 06/2005 23.5 18.1
## 2 2006 02/06/2005 07/2005 26.2 22.8
## 3 2007 03/06/2005 08/2005 30.1 23.9
## 4 2008 04/06/2005 09/2005 29.5 25.1
## 5 2009 05/06/2005 10/2005 24.6 25.0
Reference example
amBarplot(x = "country", y = "visits", data = data_bar,
labelRotation = -45)
Horizontal bar
amBarplot(x = "country", y = "visits", data = data_bar, horiz = TRUE)
3D bar
amBarplot(x = "country", y = "visits", data = data_bar, depth = 15, labelRotation = -90)
Display values
amBarplot(x = "country", y = "visits", data = data_bar, show_values = TRUE, labelRotation = -90)
Grouped columns
amBarplot(x = "year", y = c("income", "expenses"), data = data_gbar)
Parse dates - default label: first day of each year
pipeR::pipeline(
amBarplot(x = "year", y = c("income", "expenses"), data = data_gbar,
dataDateFormat = "YYYY", minPeriod = "YYYY"),
setChartCursor()
)
Parse dates - default label: first day of each month
pipeR::pipeline(
amBarplot(x = "month", y = c("income", "expenses"), data = data_gbar,
dataDateFormat = "MM/YYYY", minPeriod = "MM"),
setChartCursor()
)
Change groups colors
amBarplot(x = "year", y = c("income", "expenses"), data = data_gbar,
groups_color = c("#87cefa", "#c7158"))
Stacked bars
amBarplot(x = "year", y = c("income", "expenses"), data = data_gbar, stack_type = "regular")
100% Stacked bars
amBarplot(x = "year", y = c("income", "expenses"), data = data_gbar, stack_type = "100")
Layered bars
amBarplot(x = "year", y = c("income", "expenses"), data = data_gbar, layered = TRUE)
Data with row names
dataset <- data.frame(get(x = "USArrests", pos = "package:datasets"))
amBarplot(y = c("Murder", "Assault", "UrbanPop", "Rape"), data = dataset, stack_type = "regular")
amOptions
legend
amBarplot(x = "year", y = c("income", "expenses"), data = data_gbar, legend = TRUE)
#or
amBarplot(x = "year", y = c("income", "expenses"), data = data_gbar) %>>%
amOptions(legend = TRUE)
legendPosition
amBarplot(x = "year", y = c("income", "expenses"), data = data_gbar, legend = TRUE, legendPosition = "left")
#or
amBarplot(x = "year", y = c("income", "expenses"), data = data_gbar) %>>%
amOptions(legend = TRUE, legendPosition = "left")
export
amBarplot(x = "country", y = "visits", data = data_bar, labelRotation = -45, export = TRUE)
#or
amBarplot(x = "country", y = "visits", data = data_bar, labelRotation = -45) %>>%
amOptions(export = TRUE)
exportFormat
amBarplot(x = "country", y = "visits", data = data_bar, labelRotation = -45, export = TRUE,
exportFormat = "JPG")
#or
amBarplot(x = "country", y = "visits", data = data_bar, labelRotation = -45) %>>%
amOptions(export = TRUE, exportFormat = "JPG")
main and creditsPosition
amBarplot(x = "country", y = "visits", data = data_bar, labelRotation = -45, main = "My Barchart",
mainColor = "#68838B", mainSize = 25, creditsPosition = "top-right")
#or
amBarplot(x = "country", y = "visits", data = data_bar, labelRotation = -45) %>>%
amOptions( main = "My Barchart",
mainColor = "#68838B", mainSize = 25, creditsPosition = "top-right")
theme
amBarplot(x = "year", y = c("income", "expenses"), data = data_gbar,
theme = "patterns")
#or
amBarplot(x = "year", y = c("income", "expenses"), data = data_gbar) %>>%
amOptions(theme = "patterns")