Learn R Programming

toaster (version 0.5.5)

createBubblechart: Create Bubble Chart type of plot.

Description

Create a bubble chart that utilizes three dimensions of data. It is a variation of the scatter plot with data points replaced with shapes ("bubbles"): x and y are bubble location and z is its size. It can optionally assign data points labels and fill shapes with colors.

Usage

createBubblechart(data, x, y, z, label = z, fill = NULL, facet = NULL, ncol = 1, facetScales = "fixed", xlim = NULL, baseSize = 12, baseFamily = "sans", shape = 21, shapeColour = "black", scaleSize = TRUE, shapeSizeRange = c(3, 10), shapeMaxSize = 100, paletteValues = NULL, palette = "Set1", title = paste("Bubble Chart by", fill), subtitle = NULL, xlab = x, ylab = y, labelSize = 5, labelFamily = "", labelFontface = "plain", labelColour = "black", labelVJust = 0.5, labelHJust = 0.5, labelAlpha = 1, labelAngle = 0, legendPosition = "right", sizeGuide = FALSE, fillGuide = "colorbar", defaultTheme = theme_tufte(base_size = baseSize, base_family = baseFamily), themeExtra = NULL)

Arguments

data
data frame contains data computed for bubblechart
x
name of a column containing x variable values
y
name of a column containing y variable values
z
name of a column containing bubble size value
label
name of a column containing bubble label
fill
name of a column with values to use for bubble colours
facet
vector of 1 or 2 column names to split up data to plot the subsets as facets. If single name then subset plots are placed next to each other, wrapping with ncol number of columns (uses facet_wrap). When two names then subset plots vary on both horizontal and vertical directions (grid) based on the column values (uses facet_grid).
ncol
number of facet columns (applies when single facet column supplied only - see parameter facet).
facetScales
Are scales shared across all subset plots (facets): "fixed" - all are the same, "free_x" - vary across rows (x axis), "free_y" - vary across columns (Y axis, default), "free" - both rows and columns (see in facet_wrap parameter scales )
xlim
a vector specifying the data range for the x scale and the default order of their display in the x axis.
baseSize
theme base font size
baseFamily
theme base font family
shape
bubble shape
shapeColour
colour of shapes
scaleSize
logical if TRUE then scale the size of shape to be proportional to the value, if FALSE then scale the area.
shapeSizeRange
bubble size range (applies only when scaleSize = TRUE)
shapeMaxSize
size of largest shape (applies only when scaleSize = FALSE)
paletteValues
actual palette colours for use with scale_fill_manual (if specified then parameter palette is ignored)
palette
Brewer palette name - see display.brewer.all in RColorBrewer package for names
title
plot title.
subtitle
plot subtitle.
xlab
a label for the x axis, defaults to a description of x.
ylab
a label for the y axis, defaults to a description of y.
labelSize
size of labels
labelFamily
label font name or family name
labelFontface
label font face (c("plain","bold","italic","bold.italic"))
labelColour
color of labels
labelVJust
position of the anchor (0=bottom edge, 1=top edge), can go below 0 or above 1
labelHJust
position of the label anchor (0=left edge, 1=right edge), can go below 0 or above 1
labelAlpha
the transparency of the text label
labelAngle
the angle at which to draw the text label
legendPosition
the position of legends. ("left", "right", "bottom", "top", or two-element numeric vector). "none" is no legend.
sizeGuide
Name of guide object, or object itself for the z (bubble size). Typically "legend" name or object guide_legend.
fillGuide
Name of guide object, or object itself for the fill. Typically "colorbar" name or object guide_colourbar.
defaultTheme
plot theme settings with default value theme_tufte. More themes are available here: ggtheme (by ggplot2) and ggthemes.
themeExtra
any additional theme settings that override default theme.

Value

ggplot object

See Also

computeAggregates computes data for the bubble chart.

Examples

Run this code
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>")

cormat = computeCorrelations(channel=conn, "pitching_enh", sqlColumns(conn, "pitching_enh"), 
                             include = c('w','l','cg','sho','sv','ipouts','h','er','hr','bb',
                                         'so','baopp','era','whip','ktobb','fip'),
                             where = "decadeid = 2000", test=FALSE)
# remove duplicate correlation values (no symmetry)
cormat = cormat[cormat$metric1 < cormat$metric2, ]
createBubblechart(cormat, "metric1", "metric2", "value", label=NULL, fill="sign")
}

Run the code above in your browser using DataLab