Description Usage Arguments Value Note Author(s) References See Also Examples
The gvisGeoChart 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 geo chart is a map of a country, a continent, or a region with two modes: The region mode colorizes whole regions, such as countries, provinces, or states. The marker mode marks designated regions using bubbles that are scaled according to a value that you specify.
A geo chart is rendered within the browser using SVG or VML. Note that the map is not scrollable or draggable.
1 2 | gvisGeoChart(data, locationvar = "", colorvar="",
sizevar="", hovervar="", options = list(), chartid)
|
data |
a |
locationvar |
column name of
|
colorvar |
column name of |
sizevar |
only used for |
hovervar |
column name of |
options |
list of configuration options for Google Geo Chart.
Further possible components are, taken from https://google-developers.appspot.com/chart/interactive/docs/gallery/geochart.html#Configuration_Options:
|
chartid |
character. If missing (default) a random chart id will be generated based on
chart type and |
gvisGeoChart
returns list of class
"gvis
" and "list
".
An object of class "gvis
" is a list containing at least the following components:
|
Google visualisation type, here 'GeoChart' |
|
character id of the chart object. Unique chart ids are required to place several charts on the same page. |
|
a list with the building blocks for a page
|
This is the new version of the GeoChart chart.
Markus Gesmann markus.gesmann@gmail.com,
Diego de Castillo decastillo@gmail.com
Google Geo Chart API: https://google-developers.appspot.com/chart/interactive/docs/gallery/geochart.html
Follow the link for Google's data policy.
See also print.gvis
, plot.gvis
for
printing and plotting methods, gvisGeoMap
and
gvisIntensityMap
for an alternative to gvisGeoChart
.
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | ## Please note that by default the googleVis plot command
## will open a browser window and requires Internet
## connection to display the visualisation.
## Regions examples
## The regions style fills entire regions (typically countries) with
## colors corresponding to the values that you assign
G1 <- gvisGeoChart(Exports, locationvar='Country', colorvar='Profit')
plot(G1)
## Plot only Europe
G2 <- gvisGeoChart(Exports, "Country", "Profit",
options=list(region="150"))
plot(G2)
## Example showing US data by state
require(datasets)
states <- data.frame(state.name, state.x77)
G3 <- gvisGeoChart(states, "state.name", "Illiteracy",
options=list(region="US", displayMode="regions", resolution="provinces",
width=600, height=400))
plot(G3)
## Markers Example
## A marker style map renders bubble-shaped markers at specified
## locations with the color and size that you specify.
G4 <- gvisGeoChart(CityPopularity, locationvar='City', colorvar='Popularity',
options=list(region='US', height=350,
displayMode='markers',
colorAxis="{values:[200,400,600,800],
colors:[\'red', \'pink\', \'orange',\'green']}")
)
plot(G4)
G5 <- gvisGeoChart(Andrew, "LatLong", colorvar='Speed_kt',
options=list(region="US"))
plot(G5)
G6 <- gvisGeoChart(Andrew, "LatLong", sizevar='Speed_kt',
colorvar="Pressure_mb", options=list(region="US"))
plot(G6)
## Create lat:long values and plot a map of Oceania
## Set background colour to light-blue
require(stats)
data(quakes)
head(quakes)
quakes$latlong<-paste(quakes$lat, quakes$long, sep=":")
G7 <- gvisGeoChart(quakes, "latlong", "depth", "mag",
options=list(displayMode="Markers", region="009",
colorAxis="{colors:['red', 'grey']}",
backgroundColor="lightblue"))
plot(G7)
## Not run:
# Plot S&P countries' credit rating sourced from Wikipedia
# Use the hovervar to show the rating
library(XML)
url <- "http://en.wikipedia.org/wiki/List_of_countries_by_credit_rating"
x <- readHTMLTable(readLines(url), which=3)
levels(x$Rating) <- substring(levels(x$Rating), 4,
nchar(levels(x$Rating)))
x$Ranking <- x$Rating
levels(x$Ranking) <- nlevels(x$Rating):1
x$Ranking <- as.character(x$Ranking)
x$Rating <- paste(x$Country, x$Rating, sep=": ")
#### Create a geo chart
G8 <- gvisGeoChart(x, "Country", "Ranking", hovervar="Rating",
options=list(gvis.editor="S&P",
colorAxis="{colors:['#91BFDB', '#FC8D59']}"))
plot(G8)
## Plot world wide earth quakes of the last 30 days with magnitude >= 4.0
library(XML)
## Get earthquake data of the last 30 days
eq <- read.csv("http://earthquake.usgs.gov/earthquakes/feed/v0.1/summary/2.5_week.csv")
eq$loc=paste(eq$Latitude, eq$Longitude, sep=":")
G9 <- gvisGeoChart(eq, "loc", "Depth", "Magnitude",
options=list(displayMode="Markers",
colorAxis="{colors:['purple', 'red', 'orange', 'grey']}",
backgroundColor="lightblue"), chartid="EQ")
plot(G9)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.