File: Trendlines.R

package info (click to toggle)
r-cran-googlevis 0.6.2-1~bpo8+1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 2,968 kB
  • sloc: sh: 17; makefile: 5
file content (52 lines) | stat: -rw-r--r-- 1,629 bytes parent folder | download | duplicates (4)
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
## Trend line demo
# A trendline is a line superimposed on a chart revealing the overall direction 
# of the data. Google Charts can automatically generate trendlines for 
# Scatter Charts, Bar Charts, Column Charts, and Line Charts.
# 
# Fore more details see:
# https://developers.google.com/chart/interactive/docs/gallery/trendlines

## Linear trend line

## Add a trend line to the first series
## ---- LinearTrend ----
plot(
  gvisScatterChart(women, options=list(trendlines="0"))
)

## ---- ExponentialTrend ----
plot(
  gvisScatterChart(women, options=list(
    trendlines="{0: { type: 'exponential',  
                     visibleInLegend: 'true', 
                     color: 'green',
                     lineWidth: 10,
                     opacity: 0.5}}",
    chartArea="{left:50,top:20,width:'50%',height:'75%'}"))
)

## ---- ColumnChartWithTrendline ----
dat <- data.frame(val1=c(1,3,4,5,6,8), 
                  val2=c(12,23,32,40,50,55))
plot(
  gvisColumnChart(dat,
                  options=list(trendlines="{0: {}}"))
)

## ---- DifferentLabels ----
dat$val3 <- c(5,6,10,12,15,20)
plot(
  gvisColumnChart(dat,
                  options=list(trendlines="{
                          0: {
                            labelInLegend: 'Trendline 1',
                            visibleInLegend: true,}, 
                          1:{
                            labelInLegend: 'Trendline 2',
                            visibleInLegend: true}
                          }",
                          chartArea="{left:50,top:20,
                                      width:'50%',height:'75%'}"
                  ))
)