Learn R Programming

rAmCharts (version 2.0.2)

amBarplot: Plotting bar chart using rAmCharts

Description

amBarplot computes a bar chart of the given values.

Usage

amBarplot(x, y, data, xlab = "", ylab = "", groups_color = NULL, horiz = FALSE, stack_type = "none", layered = FALSE, show_values = FALSE, depth = 0, dataDateFormat = NULL, minPeriod = ifelse(!is.null(dataDateFormat), "DD", ""), ...)

Arguments

x
character, column name for x-axis or numeric, value of the corresponding column. It is optional if argument data has row names.
y
character, column name for y-axis or numeric vector 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
data.frame, 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 ('
' for a new line). See data_bar and data_gbar.
xlab
character, label for x-axis.
ylab
character, label for y-axis.
groups_color
character, vector of colors in hexadecimal, same length as y.
horiz
logical, TRUE for an horizontal chart, FALSE for a vertical one If 'horiz' is set to TRUE, the setting 'labelRotation' will be ignored.
stack_type
character, "regular" if you wish stacked bars, "100" if you want 100 percent stacked bars. Default is set to "none".
layered
logical, TRUE for layered bars. If TRUE, stack_type must be set to "none".
show_values
logical, TRUE to display values.
depth
numeric, if > 0, chart is displayed in 3D. Value between 0 and 100.
dataDateFormat
character, default set to NULL. Even if your chart parses dates, you can pass them as strings in your dataframe - all you need to do is to set data date format and the chart will parse dates to date objects. Check this page for available formats. Please note that two-digit years (YY) as well as literal month names (MMM) are NOT supported in this setting.
minPeriod
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 minute increments.
...
see amOptions for more options.

Value

An object of class AmChart.

Details

Notice about labels: 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...

See Also

Examples

Run this code
# Data
data(data_bar)
data(data_gbar)

amBarplot(x = "country", y = "visits", data = data_bar)
amBarplot(x = "year", y = c("income", "expenses"), data = data_gbar)
## Not run: 
# # shortcut
# amBarplot(x = "year", y = c("inc", "exp"), data = data_gbar)
# ## End(Not run)


# Other examples available which can be time consuming depending on your configuration.

library(pipeR)

# Test with label rotation
amBarplot(x = "country", y = "visits", data = data_bar, labelRotation = -45) 

# Horizontal bar
amBarplot(x = "country", y = "visits", data = data_bar, horiz = TRUE, labelRotation = -45)

# 3D bar
amBarplot(x = "country", y = "visits", data = data_bar, depth = 15, labelRotation = -45)

# Display values
amBarplot(x = "country", y = "visits", data = data_bar, show_values = TRUE, labelRotation = -45)

# Grouped columns
amBarplot(x = "year", y = c("income", "expenses"), data = data_gbar)

# Parse dates
# Default label: first day of each year
amBarplot(x = "year", y = c("income", "expenses"), data = data_gbar,
          dataDateFormat = "YYYY", minPeriod = "YYYY")

amBarplot(x = "month", y = c("income", "expenses"), data = data_gbar,
          dataDateFormat = "MM/YYYY", minPeriod = "MM")

amBarplot(x = "day", y = c("income", "expenses"), data = data_gbar,
          dataDateFormat = "DD/MM/YYYY")
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")


# Round values
amBarplot(x = "year", y = c("in", "ex"), data = data_gbar, precision = 0)


Run the code above in your browser using DataLab