chartql Documentation


ChartQL uses a very simple syntax for the user to specify what kind of plot(s) they want to generate without having to remember complicated syntax. The ChartQL library uses ggplot2 and manages all the syntax complexities internally. As an example, to generate a bar chart of company sales faceted by product category further faceted by season of the year, we simply write:

CHART bar X category, season Y sales


cql (source_frame, cql_string)

Parameter | Description | | --- | --- | |source_frame | DataFrame object. Used as the source to build the plot.| |cql_string | ChartQL query string. Used to specify options in terms of how to build the plot. This includes the type of plot, choice of x and y variables, axis titles and more. Full parameter list below.


The ChartQL query language uses a fairly simple format to let users generate amazing plots but with minimal scripting, allowing for much faster prototyping. The ChartQL string uses the following general format:

CHART X Y (Options) \

The main variables that are required for all types of plots are:

| Prefix | Argument | Description | | --- | --- | --- | |Chart | | bar \| scatter \| hist \| line| |X| , () | X-axis variable. May include a second categorical variable (comma separated)| |Y | y_var | Y-axis variable. *Not used for hist.|

Optional Variables

All optional variable values must be enclosed in single-quotes.

| Prefix | Argument | Description | | --- | --- | --- | |X_label | '\' | X-axis custom label. Defaults to <x_var>| |Y_label | '\' | Y-axis custom label. Defaults to <y_var>| |Legend | '\' | Legend custom label. Defaults to <x_category>| |Colorset | '\' | Custom set of colors for <x_category> levels. Must be comma-separated list.| |AggFunc | '\' | Summary function for bar type. Valid types: mean \| median \| count \| sumDefaults to mean.| |Fit | '\' | Valid types: true \| false. Fit linear line.| |ConfInt | '\' | Show error bars. Value is confidence interval value. E.g. '.95' |


# Test data

dframe <- mtcars
# transform to categorical
dframe$cyl <- factor(dframe$cyl);
dframe$am <- factor(dframe$am);
dframe$vs <- factor(dframe$vs);

# Bar chart with number of cylinders on X and mpg value on Y. Default aggregation by mean:

cql_str <- "CHART bar X cyl Y mpg";
cql(dframe, cql_str);

# Same as above but faceting unique number of cylinders by am (auto vs manual):

cql_str <- "CHART bar X cyl, am Y mpg";
cql(dframe, cql_str);

# Bar chart with am color-coded purple vs orange:

cql_str <- "CHART bar X cyl, am Y mpg Colorset '#990099, #FF9900'";
cql(dframe, cql_str);

# Bar chart with 95% confidence error bars

cql_str <- "CHART bar X cyl, am Y mpg ConfInt '.95'";
cql(dframe, cql_str);

# Scatter plot of displacement vs mpg

cql_str <- "CHART scatter X disp Y mpg";
cql(dframe, cql_str);

# Scatter plot faceted by number of cylinders

cql_str <- "CHART scatter X disp, cyl Y mpg";
cql(dframe, cql_str);

# Scatter plot with linear fit and no standard error (SE) bands

cql_str <- "CHART scatter X disp, cyl Y mpg Fit 'false'";
cql(dframe, cql_str);


For any feedback, bug reports or questions, please contact:

Try the chartql package in your browser

Any scripts or data that you put into this service are public.

chartql documentation built on May 2, 2019, 6:13 a.m.