Debian Codegraph @

demo/Trendlines.R

raw
1 ## Trend line demo
2 # A trendline is a line superimposed on a chart revealing the overall direction
3 # of the data. Google Charts can automatically generate trendlines for
4 # Scatter Charts, Bar Charts, Column Charts, and Line Charts.
5 #
6 # Fore more details see:
7 # https://developers.google.com/chart/interactive/docs/gallery/trendlines
8
9 ## Linear trend line
10
11 ## Add a trend line to the first series
12 ## ---- LinearTrend ----
13 plot(
14 gvisScatterChart(women, options=list(trendlines="0"))
15 )
16
17 ## ---- ExponentialTrend ----
18 plot(
19 gvisScatterChart(women, options=list(
20 trendlines="{0: { type: 'exponential',
21 visibleInLegend: 'true',
22 color: 'green',
23 lineWidth: 10,
24 opacity: 0.5}}",
25 chartArea="{left:50,top:20,width:'50%',height:'75%'}"))
26 )
27
28 ## ---- ColumnChartWithTrendline ----
29 dat <- data.frame(val1=c(1,3,4,5,6,8),
30 val2=c(12,23,32,40,50,55))
31 plot(
32 gvisColumnChart(dat,
33 options=list(trendlines="{0: {}}"))
34 )
35
36 ## ---- DifferentLabels ----
37 dat$val3 <- c(5,6,10,12,15,20)
38 plot(
39 gvisColumnChart(dat,
40 options=list(trendlines="{
41 0: {
42 labelInLegend: 'Trendline 1',
43 visibleInLegend: true,},
44 1:{
45 labelInLegend: 'Trendline 2',
46 visibleInLegend: true}
47 }",
48 chartArea="{left:50,top:20,
49 width:'50%',height:'75%'}"
50 ))
51 )
52