library(googleVis)
demo(googleVis)
#------------------------------------------
#Line Chart
df=data.frame(country=c("US","GB","BR"),
val1=c(10,13,14),
val2=c(23,12,32)) #数据录入
line<-gvisLineChart(df)
plot(line)
#Line chart with two axis
line2<-gvisLineChart(df,"country",c("val1","val2"),
options=list(
series="[{targetAxisIndex:0},
{targetAxisIndex:1}]",
vAxes="[{title:'val1'},{title:'val2'}]"
))
plot(line2)
#---------------------------------------------
#Bar Chart
bar<-gvisBarChart(df)
plot(bar)
#---------------------------------------------
#Column Chart
column<-gvisColumnChart(df)
plot(column)
#-------------------------------------------
#Stepped Area Chart
steppedArea<-gvisSteppedAreaChart(df,xvar="country",
yvar=c("val1","val2"),
options=list(isStacked=T))
plot(steppedArea)
#-----------------------------------------------------
#Gauge
Gauge<-gvisGauge(CityPopularity,
options=list(min=0,max=800,
greenFrom=500,greenTo=800,
yellowFrom=300,yellowTo=500,
redFrom=0,redTo=300,
width=400,height=300))
plot(Gauge)
#-----------------------------------------------------
#Intensity Map
Intensity<-gvisIntensityMap(df)
plot(Intensity)
#Geo Chart
Geo=gvisGeoChart(Exports,locationvar="Country",
colorvar="Profit",
options=list(projection="kavrayskiy-vii"))
plot(Geo)
#------------------------------------------------------------
#Google Maps
AndrewMap<-gvisMap(Andrew,"LatLong","Tip", #经纬表示
options=list(showTip=TRUE,
showLine=TRUE,
enableScrollWheel=TRUE,
mapType='terrain',
useMapTypeControl=TRUE))
plot(AndrewMap)
#--------------------------------------------------------
#Org Chart
org<-gvisOrgChart(Regions,
options=list(width=600,height=250,
size='large',allowCollapse=TRUE))
plot(org)
#-------------------------------------------------------
#Tree Map
Tree <- gvisTreeMap(Regions,
"Region", "Parent",
"Val", "Fac",
options=list(fontSize=16))
plot(Tree)
#-----------------------------------------------------------
#Annotation Chart
Anno<-gvisAnnotationChart(Stock, #Data
datevar="Date",
numvar="Value",
idvar="Device",
titlevar="Title",
annotationvar="Annotation",
options=list(
width=600,height=350,
fill=10,displayExactValues=T,
colors="['#0000ff','#00ff00']")
)
plot(Anno)
#-----------------------------------------------------------
#Sankey chart
datSK <- data.frame(From=c(rep("A",3), rep("B", 3)),
To=c(rep(c("X", "Y", "Z"),2)),
Weight=c(5,7,6,2,9,4))
Sankey <- gvisSankey(datSK, from="From", to="To", weight="Weight",
options=list(
sankey="{link: {color: { fill: '#d799ae' } },
node: { color: { fill: '#a61d4c' },
label: { color: '#871b47' } }}"))
plot(Sankey)
#----------------------------------------------------------
#Calendar chart
Cal <- gvisCalendar(Cairo,
datevar="Date",
numvar="Temp",
options=list(
title="Daily temperature in Cairo",
height=320,
calendar="{yearLabel: { fontName: 'Times-Roman',
fontSize: 32, color: '#1A8763', bold: true},
cellSize: 10,
cellColor: { stroke: 'red', strokeOpacity: 0.2 },
focusedCellColor: {stroke:'red'}}")
)
plot(Cal)
#--------------------------------------------------------
#Merging Charts
#Merge2
G <- gvisGeoChart(Exports, "Country", "Profit",
options=list(width=300, height=300))
T <- gvisTable(Exports,
options=list(width=220, height=300))
GT <- gvisMerge(G,T, horizontal=TRUE)
plot(GT)
#Merge 3
M <- gvisMotionChart(Fruits, "Fruit", "Year",
options=list(width=400, height=410))
GTM <- gvisMerge(GT, M, horizontal=TRUE,
tableOptions="cellspacing=10")
plot(GTM)
#Merge 4
line <- gvisLineChart(OpenClose, "Weekday", c("Open", "Close"),
options=list(legend='none', width=300, height=150))
column <- gvisColumnChart(OpenClose, "Weekday", c("Open", "Close"),
options=list(legend='none', width=300, height=150))
area <- gvisAreaChart(OpenClose, "Weekday", c("Open", "Close"),
options=list(legend='none', width=300, height=150))
bar <- gvisBarChart(OpenClose, "Weekday", c("Open", "Close"),
options=list(legend='none', width=300, height=150))
LBCA <- gvisMerge(gvisMerge(line, bar), gvisMerge(column, area),
horizontal=TRUE, tableOptions="bgcolor=\"#AABBCC\"")
plot(LBCA)
print(GTM,file="GTM.html") #保存成网页