library(magrittr) alog <- open_profile_as_json("./data-raw/21-02-17_1840_ZambiaKasama_1stcrack.alog") profile <- clean_raw_alog(alog) # colors for the 3 phase bars on top phase_colors <- c('#4DB848', '#FF9673', '#E1C8B4')
phase_times <- prepare_phase_times(profile) times_temps <- times_temps_deltas_as_df(profile) #%>% dplyr::mutate_if(is.character, as.integer)
plotly::plot_ly( data = times_temps, x = ~ Time2 # Time2 starts at charge time ) %>% plotly::add_lines( data = times_temps, # ET Line type = 'scatter', mode = 'lines', line = list(color = "#4DB848"), y = ~ BT, # hovertemplate = paste('%{y: .1f}\u00b0F', '<br>%{x}<br>'), hovertemplate = '%{y: .1f}\u00b0F', showlegend = FALSE, name = "BT" ) %>% plotly::add_lines( data = times_temps, # ET Line type = 'scatter', mode = 'lines', line = list(color = "#D50032"), y = ~ ET, # hovertemplate = paste('%{y: .1f}\u00b0F', '<br>%{x}<br>'), hovertemplate = '%{y: .1f}\u00b0F', showlegend = FALSE, name = "ET" ) %>% plotly::layout(hovermode = "x unified") %>% # plotly::add_annotations( # Special events # data = special_times, # x = ~ lubridate::as_datetime(as.numeric(time_of_event)), # # y = ~ jitter(400, 60), # y = ~ 10, # text = ~ type_of_event, # # yaxis = "y2", # textposition = "top center", # showarrow = FALSE, # # arrowhead = .5, # # arrowwidth = 1, # font = list(size = 12, color = "#ffffff"), # bgcolor = ~ color # ) %>% # Add lines for phases plotly::add_lines( data = times_temps, # Change BT Line mode = 'lines', x = ~ Time2, y = ~ dtemp1, line = list(color = "#428BCA"), name = "\u0394ET", hovertemplate = '%{y: .1f}\u00b0F', showlegend = FALSE, yaxis = "y2" ) %>% plotly::add_lines( data = times_temps, # Change ET Line mode = 'lines', x = ~ Time2, y = ~ dtemp2, line = list(color = "#3f0585"), name = "\u0394BT", hovertemplate = '%{y: .1f}\u00b0F', showlegend = FALSE, yaxis = "y2" ) %>% plotly::layout( xaxis = list(# gridcolor = toRGB("gray85"), title = "", zeroline = F, showline = F, showgrid = F, # tick0 = "00:00", tick0 = 0, ticks = "inside", tickcolor = "rgb(245,245,245)", tickformat = "%M:%S", # tickmode = "linear", dtick = 30 # Tick every 30 seconds ), # The right side y-axis yaxis2 = list( zeroline = F, showline = F, showgrid = F, tickfont = list(color = "#428BCA"), ticksuffix = "\u00b0F", overlaying = "y", side = "right", title = "" ), yaxis = list( title = "", ticksuffix = "\u00b0F", zeroline = F, showline = F, showgrid = F ), margin = list( r = 30, l = 0, b = 0, t = 0 ), plot_bgcolor = '#fff', # make white background paper_bgcolor = '#fff' ) %>% # Add 3 phases on top plotly::add_bars( data = phase_times, x =~ phase_time, y = ~ 500, name = ~ name, width = 25, text =~ name, #? orientation = 'h', showlegend = FALSE, marker = list(color = phase_colors) ) %>% plotly::layout(barmode = 'stack') %>% plotly::add_text(data = phase_times, x =~ label_point, text =~ paste0(name,": ",percent,"%"),y = 500, textposition = "right", textfont = list(size = 12, color = "#ffffff"))
# mess with format x=lubridate::as_datetime(as.numeric(times$time)) lubridate::hms(x) lubridate::minute(x) lubridate::seconds(x) lubridate::seconds_to_period(as.numeric(times$time)) %>% lubridate::ms() # THIS? lubridate::fast_strptime(x, format = "%H%M") (parse_date_time2(times$time)) sub(":\\d{2}", "", times((minutes%/%60 + minutes%%60 /3600)/24)) as.numeric(times$time)%/%60 + as.numeric(times$time)%%60 /3600
plotly::plot_ly( # BT Line times_temps, type = 'scatter', mode = 'lines', x = ~ Time2, line = list(color = "#4DB848"), # x = ~seq(ms("00:00"), ms("10:10")), # x = ~ lubridate::ms(Time2), # x = ~ lubridate::as_datetime(Time1), y = ~ BT, # hovertemplate = paste('%{y: .1f}\u00b0F', '<br>%{x}<br>'), hovertemplate = '%{y: .1f}\u00b0F', showlegend = FALSE, name = "BT" ) %>% plotly::layout( xaxis = list(# gridcolor = toRGB("gray85"), title = "", zeroline = F, showline = F, showgrid = F, tick0 = "00:00", # tick0 = 0, ticks = "inside", tickcolor = "rgb(245,245,245)", tickformat = "%M:%S", # tickmode = "linear", dtick = 30 # Tick every 30 seconds ))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.