gvisPieChart: Google Pie Chart with R

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

Description

The gvisPieChart 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. The actual chart is rendered by the web browser using SVG or VML.

Usage

1
gvisPieChart(data, labelvar = "", numvar = "", options = list(), chartid)

Arguments

data

a data.frame to be displayed as a pie chart

labelvar

Name of the character column which contains the category labels for the slice labels.

numvar

a vector of column names of the numerical variables of the slice values.

options

list of configuration options for Google Pie 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/piechart.html#Configuration_Options:

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.

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.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.

chartArea.height

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

colors

An 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'].

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.

height

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

is3D

Boolean. Default FALSE. If set to TRUE, displays a three-dimensional chart.

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.

slices

a JOSN array of objects, or object with nested objects. Default

{}.

A JSON array of objects, each describing the format of the corresponding slice in the pie. To use default values for a slice, specify an empty object

{}.

If a slice or a value is not specified, the global value will be used. Each object supports the following properties:

color

The color to use for this slice. Specify a valid HTML color string.

textStyle

Overrides the global pieSliceTextSlice for this slice.

You can specify either an array of objects, each of which applies to the slice in the order given, or you can specify an object where each child has a numeric key indicating which slice it applies to. For example, the following two declarations are identical, and declare the first slice as black and the fourth as red:

	  slices: [{color: 'black', {}, {}, {color: 'red'}]
	  slices: {0: {color: 'black'}, 3: {color: 'red'}}
	
pieSliceBorderColor

a string. Default 'white'. The color of the slices border.

pieSliceText

A string. Default 'percentage'. The content of the text displayed on the slice. Can be one of the following:

'percentage'

The percentage of the slice size out of the total.

'value'

The quantitative value of the slice.

'label'

The name of the slice.

'none'

No text is displayed.

pieSliceTextStyle

A json object. Default

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

An object that specifies the slice 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.

reverseCategories

Boolean. Default FALSE. If set to TRUE, will draw slices counterclockwise. The default is to draw clockwise.

sliceVisibilityThreshold

A number. Default 1/720. The slice relative part, below which a slice will not show individually. All slices that have not passed this threshold will be combined to a single slice, whose size is the sum of all their sizes. Default is not to show individually any slice which is smaller than half a degree.

pieResidueSliceColor

A string. Default '#ccc'. Color for the combination slice that holds all slices below sliceVisibilityThreshold.

pieResidueSliceLabel

A string. Default 'Other'. A label for the combination slice that holds all slices below sliceVisibilityThreshold.

title

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

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.

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

gvisPieChart 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 'PieChart'

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 piechart 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 Pie Chart API: http://code.google.com/apis/chart/interactive/docs/gallery/piechart.html

Follow the link for Google's data policy.

See Also

See also print.gvis, plot.gvis for printing and plotting methods

Examples

1
2
3
4
5
6
## Please note that by default the googleVis plot command
## will open a browser window and requires an internet
## connection to display the visualisation.

Pie1 <- gvisPieChart(CityPopularity)
plot(Pie1)

jburos/GoogleVis documentation built on May 18, 2019, 9:19 p.m.