学习googleVis例子

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")       #保存成网页

 

转载于:https://my.oschina.net/tedzheng/blog/711556

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值