gvisBubbleChart: Google Bubble Chart with R

Description Usage Arguments Value Warning Author(s) References See Also Examples

View source: R/gvisBubbleChart.R

Description

The gvisBubbleChart function reads a data.frame and creates text output referring to the Google Visualisation API, which can be included into a web page, or as a stand-alone page.

A bubble chart is used to visualize a data set with 2 to 4 dimensions. The first two dimensions are visualized as coordinates, the 3rd as color and the 4th as size.

The bubble chart is rendered within the browser using SVG or VML and displays tips when hovering over points.

Usage

1
2
3
gvisBubbleChart(data, idvar = "", xvar = "", yvar = "",
                      colorvar = "", sizevar = "",
                      options = list(), chartid)

Arguments

data

a data.frame to be displayed as a bubble chart. The data has to have at least three columns for idvar, xvar, and yvar.

idvar

column name of data with the bubble

xvar

column name of a numerical vector in data to be plotted on the x-axis.

yvar

column name of a numerical vector in data to be plotted on the y-axis.

colorvar

column name of data that identifies bubbles in the same series. Use the same value to identify all bubbles that belong to the same series; bubbles in the same series will be assigned the same color. Series can be configured using the series option.

sizevar

values in this column are mapped to actual pixel values using the sizeAxis option.

options

list of configuration options for Google Bubble Chart.

gvis.editor

a character label for an on-page button which opens an in-page dialog box that enables users to edit, change and customise the chart. By default no value is given and therefore no button is displayed.

Further possible components are, taken from https://google-developers.appspot.com/chart/interactive/docs/gallery/bubblechart.html#Configuration_Options:

axisTitlesPosition

a string. Default 'out'. Where to place the axis titles, compared to the chart area. Supported values:

'in'

Draw the axis titles inside the the chart area.

'out'

Draw the axis titles outside the chart area.

'none'

Omit the axis titles.

backgroundColor

a string or object. Default 'white'. The background color for the main area of the chart. Can be either a simple HTML color string, for example: 'red' or '#00cc00', or an object with the following properties.

backgroundColor.stroke

a string. Default '#666'. The color of the chart border, as an HTML color string.

backgroundColor.strokeWidth

a number. Default 0. The border width, in pixels.

backgroundColor.fill

a string. Default 'white'. The chart fill color, as an HTML color string.

bubble

a JSON object. Default NULL. An object with members to configure the visual properties of the bubbles.

bubble.opacity

a number between 0.0 - 1.0. Default 0.8. The opacity of the bubbles, where 0 is fully transparent and 1 is fully opaque.

bubble.stroke

a string. Default '#ccc'. The color of the bubbles' stroke.

bubble.textStyle

a JSON object. Default

{color: 'black', fontName: <global-font-name>, fontSize:
	  <global-font-size>}.

An object that specifies the bubble text style. The object has this format:

	  {color: <string>, fontName: <string>, fontSize: <number>}
	  

The color can be any HTML color string, for example: 'red' or '#00cc00'. Also see fontName and fontSize.

chartArea

a string. Default 'null'. An object with members to configure the placement and size of the chart area (where the chart itself is drawn, excluding axis and legends). Two formats are supported: a number, or a number followed by %. A simple number is a value in pixels; a number followed by % is a percentage. Example:

{left:20,top:0,width:\"50%\",height:\"75%\"}
chartArea.height

a number or string. Default auto. Chart area height.

chartArea.left

a number or string. Default auto. How far to draw the chart from the left border.

chartArea.top

a number or string. Default auto. How far to draw the chart from the top border.

chartArea.width

a number or string. Default auto. Chart area width.

colors

a JSON array of strings. Default 'colors'. The colors to use for the chart elements. An array of strings, where each element is an HTML color string, for example: colors:[red','#004411'].

colorAxis

a string. Default 'null' An object that specifies a mapping between colors and color column values. To specify properties of this object, you can use object literal notation, as shown here:

{minValue: 0,  colors: ['#FF0000', '#00FF00']}
colorAxis.minValue

a number. Default minimum value of color column in chart data. If present, specifies a minimum value for chart color data. Color data values of this value and lower will be rendered as the first color in the colorAxis.colors range.

colorAxis.maxValue

a number. Default maximum value of color column in chart data If present, specifies a maximum value for chart color data. Color data values of this value and higher will be rendered as the last color in the colorAxis.colors range.

colorAxis.values

a JSON array of numbers. Default 'null'. Controls how values are associated with colors. Each value is associated with the corresponding color in the colorAxis.colors array. These values apply to the color value for a region or marker. Regions are colored according to a gradient of the values specified here. Not specifying a value for this option is equivalent to specifying [minValue, maxValue].

colorAxis.colors

a JSON array of color strings. Default 'null'. Colors to assign to values in the visualization. An array of strings, where each element is an HTML color string, for example: colorAxis:

{colors:['red','#004411']}.

You must have at least two values; the gradient will include all your values, plus calculated intermediary values, with the first color as the smallest value, and the last color as the highest.

colorAxis.legend

an object. Default null. An object that specifies the style of the gradient color legend.

colorAxis.legend.position

a string. Default 'top'. Position of the legend. Can be one of the following:

'top'

Above the chart.

'bottom'

Below the chart.

'in'

Inside the chart, at the top.

'none'

No legend is displayed.

colorAxis.legend.textStyle

an object. Default

{color: 'black', fontName: <global-font-name>, fontSize:
	<global-font-size>}

An object that specifies the legend text style. The object has this format:

	  {color: <string>, fontName: <string>, fontSize: <number>}
	  

The color can be any HTML color string, for example:

'red'

or

'#00cc00'

. Also see fontName and fontSize.

colorAxis.legend.numberFormat

a string. Default 'auto'. A format string for numeric labels. This is a subset of the ICU pattern set. For instance,

{numberFormat:'.##'}

will display values

"10.66", "10.6"

, and

"10.0"

for values 10.666, 10.6, and 10.

enableInteractivity

boolean. Default TRUE. Whether the chart throws user-based events or reacts to user interaction. If false, the chart will not throw 'select' or other interaction-based events (but will throw ready or error events), and will not display hovertext or otherwise change depending on user input.

fontSize

a number. Default automatic. The default font size, in pixels, of all text in the chart. You can override this using properties for specific chart elements.

fontName

a string. Default 'Arial'. The default font face for all text in the chart. You can override this using properties for specific chart elements.

hAxis

a JSON object. Default 'null'. An object with members to configure various horizontal axis elements. To specify properties of this object, you can use object literal notation, as shown here:

{title: 'Hello', titleTextStyle: {color: '#FF0000'}}
hAxis.baseline

a number. Default automatic. The baseline for the horizontal axis. This option is only supported for a continuous axis.

hAxis.baselineColor

a string. Default 'black'. The color of the baseline for the horizontal axis. Can be any HTML color string, for example: 'red' or '#00cc00'. This option is only supported for a continuous axis.

hAxis.direction

1 or -1. Default 1. The direction in which the values along the vertical axis grow. Specify -1 to reverse the order of the values.

hAxis.format

a string. Default auto. A format string for numeric or date axis labels.

For number axis labels, this is a subset of the decimal formatting ICU pattern set. For instance,

{format:'#,###%'}.

will display values \code"1,000%", "750%", and "50%" for values 10, 7.5, and 0.5.

For date axis labels, this is a subset of the date formatting ICU pattern set. For instance,

{format:'MMM d, y'}.

will display the value "Jul 1, 2011" for the date of July first in 2011.

The actual formatting applied to the label is derived from the locale the API has been loaded with. For more details, see loading charts with a specific locale.

This option is only supported for a continuous axis.

hAxis.gridlines

a JSON object. Default null. An object with members to configure the gridlines on the horizontal axis. To specify properties of this object, you can use object literal notation, as shown here:

{color: '#333', count: 4}

This option is only supported for a continuous axis.

hAxis.gridlines.color

a string. Default '#CCC'. The color of the vertical gridlines inside the chart area. Specify a valid HTML color string.

hAxis.gridlines.count

a number. Default 5.The number of vertical gridlines inside the chart area. Minimum value is 2.

hAxis.logScale

boolean. Default FALSE. vAxis property that makes the vertical axis a logarithmic scale (requires all values to be positive). Set to TRUE for yes. This option is only supported for a continuous axis.

hAxis.textPosition

a string. Default 'out' Position of the horizontal axis text, relative to the chart area. Supported values: 'out', 'in', 'none'.

hAxis.textStyle

a JSON object. Default

{color: 'black',
	fontName: <global-font-name>, fontSize: <global-font-size>}

An object that specifies the horizontal axis text style. The object has this format:

{color: <string>, fontName: <string>, fontSize: <number>}

The color can be any HTML color string, for example: 'red' or '#00cc00'. Also see fontName and fontSize.

hAxis.title

a string. Default 'null'. hAxis property that specifies the title of the horizontal axis.

hAxis.titleTextStyle

a JSON object. Default

{color: 'black',
	fontName: <global-font-name>, fontSize: <global-font-size>}.

An object that specifies the horizontal axis title text style. The object has this format:

{color: <string>, fontName: <string>, fontSize: <number>}

The color can be any HTML color string, for example: 'red' or '#00cc00'. Also see fontName and fontSize.

hAxis.slantedText

boolean. Default automatic. If true, draw the horizontal axis text at an angle, to help fit more text along the axis; if false, draw horizontal axis text upright. Default behavior is to slant text if it cannot all fit when drawn upright. Notice that this option is available only when the hAxis.textPosition is set to 'out' (which is the default).

This option is only supported for a discrete axis.

hAxis.slantedTextAngle

a number, 1-90. Default 30. The angle of the horizontal axis text, if it's drawn slanted. Ignored if hAxis.slantedText is false, or is in auto mode, and the chart decided to draw the text horizontally.

This option is only supported for a discrete axis.

hAxis.maxAlternation

a number. Default 2. Maximum number of levels of horizontal axis text. If axis text labels become too crowded, the server might shift neighboring labels up or down in order to fit labels closer together. This value specifies the most number of levels to use; the server can use fewer levels, if labels can fit without overlapping.

This option is only supported for a discrete axis.

hAxis.showTextEvery

a number. Default automatic. How many horizontal axis labels to show, where 1 means show every label, 2 means show every other label, and so on. Default is to try to show as many labels as possible without overlapping.

This option is only supported for a discrete axis.

hAxis.maxValue

a number. Default automatic. hAxis property that specifies the highest vertical axis grid line. The actual grid line will be the greater of two values: the maxValue option value, or the highest data value, rounded up to the next higher grid mark.

This option is only supported for a continuous axis.

hAxis.minValue

a number. Default automatic. hAxis property that specifies the lowest vertical axis grid line. The actual grid line will be the lower of two values: the minValue option value, or the lowest data value, rounded down to the next lower grid mark.

This option is only supported for a continuous axis.

hAxis.viewWindowMode

a string. Default "pretty" if hAxis.viewWindow is null, "explicit" otherwise. Specifies how to scale the horizontal axis to render the values within the chart area. The following string values are supported:

'pretty'

Scale the horizontal values so that the maximum and minimum data values are rendered a bit inside the left and right of the chart area.

'maximized'

Scale the horizontal values so that the maximum and minimum data values touch the left and right of the chart area.

'explicit'

Specify the left and right scale values of the chart area. Data values outside these values will be cropped. You must specify a hAxis.viewWindow object describing the maximum and minimum values to show.

This option is only supported for a continuous axis.

hAxis.viewWindow

Object. Default NULL. Specifies the cropping range of the horizontal axis.

hAxis.viewWindow.max

A number. Default auto.

For a continuous axis

The maximum horizontal data value to render. Has an effect only if hAxis.viewWindowMode='explicit'.

For a discrete axis

The zero-based row index where the cropping window ends. Data points at this index and higher will be cropped out. In conjunction with vAxis.viewWindowMode.min, it defines a half-opened range [min, max) that denotes the element indices to display. In other words, every index such that min <= index < max will be displayed.

hAxis.viewWindow.min

A number. Default auto.

For a continuous axis

The minimum horizontal data value to render. Has an effect only if hAxis.viewWindowMode='explicit'.

For a discrete axis

The zero-based row index where the cropping window begins. Data points at indices lower than this will be cropped out. In conjunction with vAxis.viewWindowMode.max, it defines a half-opened range [min, max) that denotes the element indices to display. In other words, every index such that min <= index < max will be displayed.

height

a number. Default height of the containing element. Height of the chart, in pixels.

legend

a JSON object. Default NULL. An object with members to configure various aspects of the legend. To specify properties of this object, you can use object literal notation, as shown here:

{position: 'top', textStyle: {color: 'blue', fontSize: 16}}
legend.position

a string. Default 'right'. Position of the legend. Can be one of the following:

'right'

To the right of the chart.

'top'

Above the chart.

'bottom'

Below the chart.

'none'

No legend is displayed.

legend.textStyle

a JSON object. Default

{color: 'black',
	  fontName: <global-font-name>, fontSize: <global-font-size>}

An object that specifies the legend text style. The object has this format:

{color: <string>, fontName: <string>, fontSize:
	  <number>}

The color can be any HTML color string, for example: 'red' or '#00cc00'. Also see fontName and fontSize.

sizeAxis

a JSON object. Default NULL. An object with members to configure how values are associated with bubble size. To specify properties of this object, you can use object literal notation, as shown here:

{minValue: 0,  maxSize: 20}
sizeAxis.maxSize

a number. Default 30. Maximum radius of the largest possible bubble, in pixels.

sizeAxis.maxValue

a number. Default set to maximum value of size column in chart data. The size value (as appears in the chart data) to be mapped to sizeAxis.maxSize. Larger values will be cropped to this value.

sizeAxis.minSize

a number. Default 5. Minimum radius of the largest possible bubble, in pixels.

sizeAxis.minValue

a number. Default set to minimum value of size column in chart data. The size value (as appears in the chart data) to be mapped to sizeAxis.minSize. Smaller values will be cropped to this value.

sortBubblesBySize

boolean. Default TRUE. If true, sorts the bubbles by size so the smaller bubbles appear above the larger bubbles. If false, bubbles are sorted according to their order in data.

theme

a string. Default NULL. A theme is a set of predefined option values that work together to achieve a specific chart behavior or visual effect. Currently only one theme is available:

maximized

Maximizes the area of the chart, and draws the legend and all of the labels inside the chart area. Sets the following options:

	      chartArea: {width: '100%', height: '100%'},
	      legend: {position: 'in'},
	      titlePosition: 'in', axisTitlesPosition: 'in',
	      hAxis: {textPosition: 'in'}, vAxis: {textPosition: 'in'}
	    
title

a string. Default no title. Text to display above the chart.

titlePosition

a string. Default 'out'. Where to place the chart title, compared to the chart area. Supported values:

'in'

Draw the title inside the chart area.

'out'

Draw the title outside the chart area.

'none'

Omit the title.

titleTextStyle

a JSON object. Default

{color:'black', fontName:<global-font-name>,fontSize:<global-font-size>}.

An object that specifies the title text style. The object has this format:

{color: <string>, fontName: <string>, fontSize: <number>}

The color can be any HTML color string, for example: 'red' or '#00cc00'. Also see fontName and fontSize.

tooltip

a JSON object. Default NULL. An object with members to configure various tooltip elements. To specify properties of this object, you can use object literal notation, as shown here:

{textStyle: {color: '#FF0000'}, showColorCode: true}
tooltip.showColorCode

boolean. Default automatic. If true, show colored squares next to the series information in the tooltip. The default is true when focusTarget is set to 'category', otherwise the default is FALSE.

tooltip.textStyle

a JSON object. Default

{color: 'black',
	fontName: <global-font-name>, fontSize: <global-font-size>}

An object that specifies the tooltip text style. The object has this format:

{color: <string>, fontName: <string>, fontSize: <number>}

The color can be any HTML color string, for example: 'red' or '#00cc00'. Also see fontName and fontSize.

tooltip.trigger

The user interaction that causes the tooltip to be displayed:

'hover'

The tooltip will be displayed when the user hovers over an element.

'none'

The tooltip will not be displayed.

vAxis

a JSON object. Default 'null'. An object with members to configure various vertical axis elements. To specify properties of this object, you can use object literal notation, as shown here:

{title: 'Hello', titleTextStyle: {color: '#FF0000'}}
vAxis.baseline

a number. Default automatic. vAxis property that specifies the baseline for the vertical axis. If the baseline is smaller than the highest grid line or smaller than the lowest grid line, it will be rounded tothe closest gridline.

vAxis.baselineColor

a string. Default 'black'. vAxis property that specifies the color of the baseline for the vertical axis. Can be any HTML color string, for example: 'red' or '#00cc00'.

vAxis.direction

1 or -1. Default 1. The direction in which the values along the vertical axis grow. Specify -1 to reverse the order of the values.

vAxis.format

a string. Default auto. A format string for numeric axis labels. This is a subset of the ICU pattern set. For instance,

{format:'#,###%'}.

will display values 1,000%, 750%, and 50% for values 10, 7.5, and 0.5.

vAxis.gridlines

a JSON object. Default NULL. An object with members to configure the gridlines on the vertical axis. To specify properties of this object, you can use object literal notation, as shown here:

	  {color: '#333', count: 4}
	
vAxis.gridlines.color

a string. Default '#CCC'. The color of the vertical gridlines inside the chart area. Specify a valid HTML color string.

vAxis.gridlines.count

a number. Default 5.The number of vertical gridlines inside the chart area. Minimum value is 2.

vAxis.logScale

boolean. Default FALSE. vAxis property that makes the vertical axis a logarithmic scale (requires all values to be positive). Set to TRUE for yes.

vAxis.textPosition

a string. Default 'out'. Position of the vertical axis text, relative to the chart area. Supported values: 'out', 'in', 'none'.

vAxis.textStyle

a JSON object. Default

{color: 'black', fontName: <global-font-name>, fontSize: <global-font-size>}.

An object that specifies the vertical axis text style. The object has this format:

{color: <string>, fontName: <string>, fontSize: <number>}

The color can be any HTML color string, for example: 'red' or '#00cc00'. Also see fontName and fontSize.

vAxis.title

a string. Default no title. vAxis property that specifies a title for the vertical axis.

vAxis.titleTextStyle

a JSON object. Default

{color: 'black',
	  fontName: <global-font-name>, fontSize: <global-font-size>}.

An object that specifies the vertical axis title text style. The object has this format:

{color: <string>, fontName: <string>, fontSize: <number>}

The color can be any HTML color string, for example: 'red' or '#00cc00'. Also see fontName and fontSize.

vAxis.maxValue

a number. Default automatic. vAxis property that specifies the highest vertical axis grid line. The actual grid line will be the greater of two values: the maxValue option value, or the highest data value, rounded up to the next higher grid mark.

vAxis.minValue

a number. Default automatic. vAxis property that specifies the lowest vertical axis grid line. The actual grid line will be the lower of two values: the minValue option value, or the lowest data value, rounded down to the next lower grid mark.

vAxis.viewWindowMode

a string. Default "pretty" if vAxis.viewWindow is null, "explicit" otherwise. Specifies how to scale the vertical axis to render the values within the chart area. The following string values are supported:

'pretty'

Scale the vertical values so that the maximum and minimum data values are rendered a bit inside the top and bottom of the chart area.

'maximized'

Scale the vertical values so that the maximum and minimum data values touch the top and bottom of the chart area.

'explicit'

Specify the top and bottom scale values of the chart area. Data values outside these values will be cropped. You must specify a vAxis.viewWindow object describing the maximum and minimum values to show.

vAxis.viewWindow

a JSON object. Specifies the cropping range of the vertical axis.

vAxis.viewWindow.max

A number. Default 0. The maximum vertical data value to render.

Has an effect only if vAxis.viewWindowMode='explicit'.

vAxis.viewWindow.min

A number. Default 0. The minimum vertical data value to render.

Has an effect only if vAxis.viewWindowMode='explicit'.

width

a number. Default width of the containing element. Width of the chart, in pixels.

chartid

character. If missing (default) a random chart id will be generated based on chart type and tempfile

Value

gvisBubbleChart returns list of class "gvis" and "list".

An object of class "gvis" is a list containing at least the following components:

type

Google visualisation type, here 'BubbleChart'

chartid

character id of the chart object. Unique chart ids are required to place several charts on the same page.

html

a list with the building blocks for a page

header

a character string of a html page header: <html>...<body>,

chart

a named character vector of the chart's building blocks:

jsHeader

Opening <script> tag and reference to Google's JavaScript library.

jsData

JavaScript function defining the input data as a JSON object.

jsDrawChart

JavaScript function combing the data with the visualisation API and user options.

jsDisplayChart

JavaScript function calling the handler to display the chart.

jsFooter

End tag </script>.

jsChart

Call of the jsDisplayChart function.

divChart

<div> container to embed the chart into the page.

caption

character string of a standard caption, including data name and chart id.

footer

character string of a html page footer: </body>...</html>, including the used R and googleVis version and link to Google's Terms of Use.

Warning

Google Visualisation API: You cannot load both bubblechart and corechart packages at the same time on the same page.

Author(s)

Markus Gesmann markus.gesmann@gmail.com,

Diego de Castillo decastillo@gmail.com

References

Google Bubble Chart API: http://code.google.com/apis/chart/interactive/docs/gallery/bubblechart.html

Follow the link for Google's data policy.

See Also

See also gvisMotionChart for a moving bubble chart over time, and print.gvis, plot.gvis for printing and plotting methods.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
bubble1 <- gvisBubbleChart(Fruits, idvar="Fruit", xvar="Sales", yvar="Expenses")
plot(bubble1)

## Set color and size
bubble2 <- gvisBubbleChart(Fruits, idvar="Fruit", xvar="Sales", yvar="Expenses",
                          colorvar="Location", sizevar="Profit",
                          options=list(hAxis='{minValue:75, maxValue:125}'))

plot(bubble2)

## Use year to color the bubbles
bubble3 <- gvisBubbleChart(Fruits, idvar="Fruit", xvar="Sales", yvar="Expenses",
                           colorvar="Year", sizevar="Profit",
                           options=list(hAxis='{minValue:75, maxValue:125}'))
plot(bubble3)

## Gradient colour example
bubble4 <- gvisBubbleChart(Fruits, idvar="Fruit", xvar="Sales", yvar="Expenses",
                          sizevar="Profit",
                          options=list(hAxis='{minValue:75,  maxValue:125}', 
                                  colorAxis="{colors: ['lightblue', 'blue']}"))
plot(bubble4)

## Not run: 
## Moving bubble chart over time, aka motion chart

M <- gvisMotionChart(Fruits, Fruit, Year)
plot(M)

## End(Not run)

kleanthisk10/google-motion-charts-with-r documentation built on May 20, 2019, 12:32 p.m.