Description Usage Arguments Details Value See Also Examples
View source: R/computeBarchart.R
Compute aggregates across category class represented by the table
column. Values are one or more SQL aggregates that are valid expressions
with GROUP BY <class column>
. Class column usually is of character
or other discrete type. Typical example is computing a bar chart for the
column using SQL COUNT(*) ... GROUP BY
- hence the name of the
function. Result is a data frame to visualize as bar charts or heatmaps
(see creating visualizations with createHistogram
and
createHeatmap
).
1 2 3 |
channel |
connection object as returned by |
tableName |
table name |
category |
column name or expression associated with categories. Name may be
valid SQL expression and can contain otional alias (e.g. |
aggregates |
SQL aggregates to compute. Each aggregate corresponds to category value.
Aggregates may have optional aliases like in |
where |
specifies criteria to satisfy by the table rows before applying
computation. The creteria are expressed in the form of SQL predicates (inside
|
orderBy |
list of column names, aliases, references or their combinations to use in SQL |
top |
if specified indicates number of bars to include in bar plot. In combination with |
by |
for optional grouping by one or more columns for faceting or alike (effectively these elements
will be part of |
withMelt |
logical if TRUE then uses reshape2 |
... |
additional arguments to be passed to |
test |
logical: if TRUE show what would be done, only (similar to parameter |
No columns returned as character and not excluded by as.is
are
converted to factors by default, i.e. stringsAsFactors = FALSE
when calling
sqlQuery
if not specified when calling this function.
Data frame to use for bar chart plots with createHistogram
.
computeHistogram
, createHistogram
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | if(interactive()){
# initialize connection to Lahman baseball database in Aster
conn = odbcDriverConnect(connection="driver={Aster ODBC Driver};
server=<dbhost>;port=2406;database=<dbname>;uid=<user>;pwd=<pw>")
# Compute average team season era, walks, and hits for each decade starting with 1980
computeBarchart(channel=conn, "teams_enh", "teamid team",
aggregates=c("avg(era) era", "avg(bb) bb", "avg(h) h"),
where="yearid >=1980", by=c("decadeid"))
# multipe aggregates in the same bar chart (with melt)
bc = computeBarchart(channel=conn, tableName="pitching_enh", category="teamid",
aggregates=c("AVG(era) era", "AVG(whip) whip"), withMelt=TRUE,
where="yearid >= 2000 and lgid='AL'")
# adding facets by decadeid
bc = computeBarchart(channel=conn, tablelName="pitching_enh", category="teamid",
aggregates=c("AVG(era) era", "AVG(whip) whip", "AVG(ktobb) ktobb"),
where="yearid >= 1990 and lgid='AL'", by="decadeid", withMelt=TRUE)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.