-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobal-plot.R
189 lines (167 loc) · 14.7 KB
/
global-plot.R
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# IVA 2.5.17
library(plotly)
library(dplyr)
library(tidyr)
plotlyMarkersLines <- function(){
trace_0 <- rnorm(100, mean = 5)
trace_1 <- rnorm(100, mean = 0)
trace_2 <- rnorm(100, mean = -5)
x <- c(1:100)
data <- data.frame(x, trace_0, trace_1, trace_2)
p <- plot_ly(data, x = ~x, y = ~trace_0, name = 'trace 0', type = 'scatter', mode = 'lines') %>%
add_trace(y = ~trace_1, name = 'trace 1', mode = 'lines+markers') %>%
add_trace(y = ~trace_2, name = 'trace 2', mode = 'markers') %>%
layout(title = "title",
xaxis = list(title = "Days"),
yaxis = list(title = "Temp"))
p
}
plotlyNAMarkersLines <- function(){
trace_0 <- rnorm(365, mean = 5, sd = 30)
trace_1 <- trace_0
trace_3 <- trace_0
trace_3[sample(length(trace_0), 33)] <- NA
trace_0[sample(length(trace_0), 33)] <- NA
x <- c(1:365)
data <- data.frame(x, trace_0, trace_1, trace_3)
colz <- c('#FE8268', '#81E8FE', '#FED681', '#81FED6', '#FE81A9')
p <- plot_ly(data, x = ~x,
y = ~trace_1, name = 'trace 1', type = 'scatter', mode = 'markers') %>% # , hoverinfo = "none"
add_trace(y = ~trace_0, name = 'trace 0', mode = 'markers') %>%
add_trace(y = ~trace_3, name = 'trace 3', mode = 'markers') %>%
layout(title = "title",
xaxis = list(title = "Days"),
yaxis = list(title = "Temp")) %>%
rangeslider()
p
}
plotlyVect <- function(vec.na, vec.impute, vec.title, vec.ysxis, vec.xaxis,
mode_line = FALSE, mode_slider = TRUE) {
days<- 1:length(vec.impute)
data <- data.frame(days, vec.na, vec.impute)
if (mode_line) mode.edom <- 'lines+markers'
else mode.edom <- 'markers'
if (mode_slider) {
p <- plot_ly(data, x = ~days, y= ~vec.impute, name = 'vec.impute', type = 'scatter', mode = mode.edom) %>%
add_trace(y = ~vec.na, name = 'vec.na', mode = mode.edom) %>%
layout(title = vec.title,
xaxis = list(title = vec.xaxis),
yaxis = list(title = vec.ysxis),
legend = list(x = 0, y = 1)) %>%
rangeslider()
}
else {
p <- plot_ly(data, x = ~days, y= ~vec.impute, name = 'vec.impute', type = 'scatter', mode = mode.edom) %>%
add_trace(y = ~vec.na, name = 'vec.na', mode = mode.edom) %>%
layout(title = vec.title,
xaxis = list(title = vec.xaxis),
yaxis = list(title = vec.ysxis),
legend = list(x = 0, y = 1))
}
p
}
################################
### plotlyPrecTemp
################################
library(plotly)
trace1 <- list(
x = c("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", "97", "98", "99", "100", "101", "102", "103", "104", "105", "106", "107", "108", "109", "110", "111", "112", "113", "114", "115", "116", "117", "118", "119", "120", "121", "122", "123", "124", "125", "126", "127", "128", "129", "130", "131", "132", "133", "134", "135", "136", "137", "138", "139", "140", "141", "142", "143", "144", "145", "146", "147", "148", "149", "150", "151", "152", "153", "154", "155", "156", "157", "158", "159", "160", "161", "162", "163", "164", "165", "166", "167", "168", "169", "170", "171", "172", "173", "174", "175", "176", "177", "178", "179", "180", "181", "182", "183", "184", "185", "186", "187", "188", "189", "190", "191", "192", "193", "194", "195", "196", "197", "198", "199", "200", "201", "202", "203", "204", "205", "206", "207", "208", "209", "210", "211", "212", "213", "214", "215", "216", "217", "218", "219", "220", "221", "222", "223", "224", "225", "226", "227", "228", "229", "230", "231", "232", "233", "234", "235", "236", "237", "238", "239", "240", "241", "242", "243", "244", "245", "246", "247", "248", "249", "250", "251", "252", "253", "254", "255", "256", "257", "258", "259", "260", "261", "262", "263", "264", "265", "266", "267", "268", "269", "270", "271", "272", "273", "274", "275", "276", "277", "278", "279", "280", "281", "282", "283", "284", "285", "286", "287", "288", "289", "290", "291", "292", "293", "294", "295", "296", "297", "298", "299", "300", "301", "302", "303", "304", "305", "306", "307", "308", "309", "310", "311", "312", "313", "314", "315", "316", "317", "318", "319", "320", "321", "322", "323", "324", "325", "326", "327", "328", "329", "330", "331", "332", "333", "334", "335", "336", "337", "338", "339", "340", "341", "342", "343", "344", "345", "346", "347", "348", "349", "350", "351", "352", "353", "354", "355", "356", "357", "358", "359", "360", "361", "362", "363", "364", "365"),
y = c("-426", "-441", "-447", "-433", "-415", "-417", "-403", "-412", "-433", "-452", "-467", "-462", "-446", "-433", "-452", "-442", "-433", "-416", "-441", "-462", "-452", "-472", "-373", "-375", "-428", "-477", "-412", "-425", "-447", "-333", "-320", "-371", "-407", "-347", "-355", "-371", "-413", "-388", "-387", "-368", "-377", "-423", "-455", "-471", "-460", "-461", "-441", "-343", "-367", "-397", "-416", "-392", "-388", "-386", "-353", "-293", "-221", "-241", "-291", "-320", "-316", "-328", "-322", "-318", "-322", "-308", "-291", "-238", "-263", "-268", "-236", "-251", "-261", "-233", "-208", "-193", "-218", "-206", "-196", "-201", "-188", "-186", "-171", "-183", "-133", "-138", "-138", "-138", "-145", "-120", "-114", "-110", "-125", "-161", "-125", "-101", "-135", "-150", "-154", "-135", "-114", "-77", "-95", "-86", "-67", "-22", "-22", "-6", "16", "13", "-11", "-8", "18", "52", "-2", "-40", "-22", "-8", "27", "57", "21", "16", "45", "95", "89", "96", "90", "85", "91", "114", "115", "123", "106", "100", "100", "65", "80", "131", "126", "98", "75", "101", "110", "159", "161", "111", "121", "119", "105", "125", "125", "134", "150", "146", "115", "120", "130", "118", "119", "131", "151", "156", "175", "208", "211", "223", "201", "201", "168", "130", "116", "146", "155", "146", "135", "129", "155", "168", "178", "191", "185", "200", "221", "231", "245", "251", "238", "181", "181", "168", "173", "176", "203", "185", "211", "233", "246", "243", "180", "188", "213", "241", "261", "271", "226", "228", "225", "221", "238", "240", "253", "181", "143", "140", "99", "110", "118", "136", "150", "151", "124", "171", "206", "213", "185", "158", "151", "155", "163", "158", "143", "159", "171", "155", "110", "125", "145", "153", "131", "148", "134", "150", "139", "141", "125", "105", "79", "80", "62", "70", "77", "74", "95", "80", "86", "70", "37", "47", "42", "22", "11", "22", "13", "11", "26", "33", "37", "42", "27", "28", "32", "9", "22", "-1", "-20", "-32", "-37", "-23", "-11", "-30", "-23", "-22", "-54", "-60", "-74", "-16", "-75", "-144", "-139", "-163", "-166", "-163", "-139", "-175", "-109", "-91", "-143", "-176", "-188", "-208", "-233", "-170", "-183", "-201", "-258", "-181", "-198", "-183", "-221", "-258", "-258", "-205", "-231", "-251", "-181", "-168", "-218", "-230", "-243", "-243", "-135", "-47", "-40", "-83", "-191", "-213", "-216", "-233", "-346", "-407", "-431", "-442", "-467", "-468", "-462", "-488", "-492", "-461", "-382", "-376", "-348", "-363", "-410", "-306", "-331", "-351", "-387", "-362", "-435", "-387", "-367", "-453", "-467", "-468", "-470", "-501", "-530", "-512", "-435", "-352", "-261", "-278", "-273", "-298", "-335"),
line = list(color = "rgb(220, 24, 41)"),
marker = list(
color = "rgb(220, 24, 41)",
line = list(color = "rgb(220, 24, 41)")
),
mode = "lines+markers",
name = "temp",
type = "scatter"
)
trace2 <- list(
x = c("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", "97", "98", "99", "100", "101", "102", "103", "104", "105", "106", "107", "108", "109", "110", "111", "112", "113", "114", "115", "116", "117", "118", "119", "120", "121", "122", "123", "124", "125", "126", "127", "128", "129", "130", "131", "132", "133", "134", "135", "136", "137", "138", "139", "140", "141", "142", "143", "144", "145", "146", "147", "148", "149", "150", "151", "152", "153", "154", "155", "156", "157", "158", "159", "160", "161", "162", "163", "164", "165", "166", "167", "168", "169", "170", "171", "172", "173", "174", "175", "176", "177", "178", "179", "180", "181", "182", "183", "184", "185", "186", "187", "188", "189", "190", "191", "192", "193", "194", "195", "196", "197", "198", "199", "200", "201", "202", "203", "204", "205", "206", "207", "208", "209", "210", "211", "212", "213", "214", "215", "216", "217", "218", "219", "220", "221", "222", "223", "224", "225", "226", "227", "228", "229", "230", "231", "232", "233", "234", "235", "236", "237", "238", "239", "240", "241", "242", "243", "244", "245", "246", "247", "248", "249", "250", "251", "252", "253", "254", "255", "256", "257", "258", "259", "260", "261", "262", "263", "264", "265", "266", "267", "268", "269", "270", "271", "272", "273", "274", "275", "276", "277", "278", "279", "280", "281", "282", "283", "284", "285", "286", "287", "288", "289", "290", "291", "292", "293", "294", "295", "296", "297", "298", "299", "300", "301", "302", "303", "304", "305", "306", "307", "308", "309", "310", "311", "312", "313", "314", "315", "316", "317", "318", "319", "320", "321", "322", "323", "324", "325", "326", "327", "328", "329", "330", "331", "332", "333", "334", "335", "336", "337", "338", "339", "340", "341", "342", "343", "344", "345", "346", "347", "348", "349", "350", "351", "352", "353", "354", "355", "356", "357", "358", "359", "360", "361", "362", "363", "364", "365"),
y = c("0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "2", "0", "5", "2", "11", "13", "0", "0", "5", "0", "0", "2", "2", "0", "0", "0", "0", "0", "0", "0", "0", "0", "6", "0", "0", "0", "0", "0", "0", "11", "5", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "16", "8", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "45", "0", "2", "2", "0", "0", "0", "0", "0", "0", "0", "0", "0", "1", "0", "2", "0", "0", "4", "0", "0", "0", "15", "141", "101", "0", "8", "0", "0", "33", "2", "5", "55", "22", "4", "2", "0", "45", "26", "0", "10", "9", "10", "32", "130", "5", "0", "0", "0", "0", "0", "0", "0", "35", "105", "0", "25", "0", "5", "26", "0", "0", "80", "0", "0", "0", "0", "0", "0", "0", "0", "33", "5", "55", "4", "0", "0", "2", "0", "0", "0", "0", "138", "0", "0", "0", "0", "0", "8", "0", "0", "0", "0", "0", "0", "25", "25", "0", "110", "109", "25", "8", "0", "0", "16", "0", "0", "0", "0", "0", "8", "0", "13", "0", "37", "0", "0", "0", "75", "0", "0", "0", "0", "0", "4", "0", "0", "0", "32", "125", "18", "4", "110", "0", "0", "83", "0", "0", "0", "0", "2", "0", "0", "0", "0", "0", "47", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "2", "0", "139", "2", "2", "0", "0", "0", "0", "55", "4", "0", "0", "0", "0", "2", "2", "0", "25", "18", "0", "0", "0", "0", "0", "8", "5", "6", "13", "13", "0", "0", "0", "0", "0", "21", "2", "0", "8", "5", "0", "0", "11", "0", "42", "47", "11", "23", "10", "6", "2", "11", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "4", "18", "4", "0", "13", "45", "9", "0", "22", "0", "22", "11", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"),
hoverinfo = "x+y+name",
line = list(color = "rgb(27, 7, 182)"),
marker = list(
color = "rgb(27, 7, 182)",
line = list(color = "rgb(27, 7, 182)")
),
mode = "lines+markers",
name = "prec",
#showlegend = TRUE,
type = "scatter",
xaxis = "x",
yaxis = "y2"
)
data <- list(trace1, trace2)
layout <- list(
autosize = T,
dragmode = "zoom",
hovermode = "x", #"closest",
height = '100%',
legend = list(
x = 0.393915787863,
y = -0.310102134663,
orientation = "h"),
showlegend = T,
margin = list( r = 100, t = 100, b = 80, l = 80 ),
title = "PrecTemp",
width = '100%',
xaxis = list(
autorange = TRUE,
domain = c(0, 1),
range = c(1, 366),
showspikes = TRUE,
title = "days",
type = "linear"
),
yaxis = list(
autorange = TRUE,
range = c(-574.5, 315.5),
showspikes = TRUE,
title = "temp",
type = "linear"
),
yaxis2 = list(
anchor = "x",
autorange = TRUE,
overlaying = "y",
range = c(-2, 300),
showspikes = TRUE,
title = "prec",
side = "right",
type = "linear"
)
)
plotlyPrecTemp <- function(trace1, trace2, layout, slider) {
p <- plot_ly()
p <- add_trace(p, x=trace1$x, y=trace1$y, line=trace1$line, marker=trace1$marker, mode=trace1$mode, name=trace1$name, type=trace1$type, uid=trace1$uid, xsrc=trace1$xsrc, ysrc=trace1$ysrc)
p <- add_trace(p, x=trace2$x, y=trace2$y, hoverinfo=trace2$hoverinfo, line=trace2$line, marker=trace2$marker, mode=trace2$mode, name=trace2$name, showlegend=trace2$showlegend, type=trace2$type, uid=trace2$uid, xaxis=trace2$xaxis, xsrc=trace2$xsrc, yaxis=trace2$yaxis, ysrc=trace2$ysrc)
p <- layout(p,
autosize=layout$autosize,
dragmode=layout$dragmode,
height=layout$height,
hovermode=layout$hovermode,
legend=layout$legend,
margin=layout$margin,
showlegend=layout$showlegend,
title=layout$title,
xaxis=layout$xaxis,
yaxis=layout$yaxis,
width=layout$width,
yaxis2=layout$yaxis2)
#p <- layout(p, autosize=layout$autosize, dragmode=layout$dragmode, hovermode=layout$hovermode, legend=layout$legend, showlegend=layout$showlegend, title=layout$title, xaxis=layout$xaxis, yaxis=layout$yaxis, yaxis2=layout$yaxis2)
if (slider)
p <- rangeslider(p)
p
}
if (FALSE) {
plotlyPrecTemp(trace1, trace2, layout)
}
if (FALSE){
plotlyNAMarkersLines()
}
if (FALSE){
plotlyMarkersLines()
}
if (FALSE) {
}