Plotly ignoring hoverinfo = 'skip' - r

I am creating a plot with several time series, plotting the mean value and two quantiles in the process and highlighting the region between the quantiles. Then I have a unified hoverinfo showing me all points at one point in time. I do not want this hoverinfo to display the dummy trace that is only there for the highlighting. I tried both hoverinfo = skip and hoverinfo = none, but that only hides any text info, not the trace itself in the hoverinfo.
Here is the code I have (without most "beautification parameters" such as axis width and the likes...):
###creating dummy data
test_data <- data.frame(matrix(0,nrow = 27,ncol = 4))
colnames(test_data) <- c("x","y","value","date")
test_data$x <- c(-1,-1,-1,0,0,0,1,1,1,-1,-1,-1,0,0,0,1,1,1,-1,-1,-1,0,0,0,1,1,1)
test_data$y <- c(-1,0,1,-1,0,1,-1,0,1,-1,0,1,-1,0,1,-1,0,1,-1,0,1,-1,0,1,-1,0,1)
test_data$value <- rnorm(27,mean = 5,sd = 1)
date_vec <- c(rep(as.Date("2022-01-01"),9),rep(as.Date("2022-01-02"),9),rep(as.Date("2022-01-03"),9))
test_data$date <- date_vec
x_levels <- unique(test_data$x)
y_levels <- unique(test_data$y)
avg <- data.frame(matrix(0,nrow = 3,ncol = 1))
colnames(avg) <- c("value")
avg$date <- unique(date_vec)
Q75 <- data.frame(matrix(0,nrow = 3,ncol = 1))
colnames(Q75) <- c("value")
Q75$date <- unique(date_vec)
Q25 <- data.frame(matrix(0,nrow = 3,ncol = 1))
colnames(Q25) <- c("value")
Q25$date <- unique(date_vec)
for (i in 1:length(unique(date_vec))){
avg$value[i] <- mean(test_data$value[test_data$date == unique(date_vec)[i]])
Q75$value[i] <- quantile(test_data$value[test_data$date == unique(date_vec)[i]],0.75)
Q25$value[i] <- quantile(test_data$value[test_data$date == unique(date_vec)[i]],0.25)
}
##creating plot
fig <- plot_ly()
fig <- fig %>% layout(hovermode = 'x unified')
for(i in 1:length(x_levels)){
for(j in 1:length(y_levels)){
fig <- fig %>% add_trace(data = test_data, type = 'scatter', mode = 'lines+markers',
x = test_data$date[test_data$x == x_levels[i] & test_data$y == y_levels[j]],
y = test_data$value[test_data$x == x_levels[i] & test_data$y == y_levels[j]],
showlegend = FALSE, line = list(color = 'grey'), marker = list(color = 'grey'),
hoverinfo = 'text', text = paste0("some text dependent on x and y"))
}}
fig <- fig %>% add_trace(data = Q25, type = 'scatter', mode = 'lines', name = '25%-quantile', x = Q25$date,
y = Q25$value, showlegend = TRUE, line = list(color = 'darkred', dash = 'dot'),
hoverinfo = 'text', text = paste0("some text dependent on Q25"))
fig <- fig %>% add_trace(data = avg, type = 'scatter', mode = 'lines', name = 'mean value', x = avg$date,
y = avg$value, showlegend = TRUE, line = list(color = 'darkred', dahs = 'dash'),
hoverinfo = 'text', text = paste0("some text depenent on avg"))
fig <- fig %>% add_trace(data = Q75, type = 'scatter', mode = 'lines', name = '75%-quantile', x = Q75$date,
y = Q75$value, showlegend = TRUE, line = list(color = 'darkred', dash = 'dot'),
hoverinfo = 'text', text = paste0("some text dependent on Q75"))
#### This is the dummy trace in question:
fig <- fig %>% add_trace(x = Q25$date, y = Q25$value, type = 'scatter', mode = 'lines', fill = 'tonexty',
fillcolor = 'rgba(139,0,0,0.2)', line = list(color = 'darkred', width = 0.1), showlegend = FALSE,
hoverinfo = 'skip')
print(fig)
Is this a bug? Am I missing something obvious? Is there a better way to make the highlighting that does not create an additional hoverinfo? Thanks in advance!

Alright, this answer is not ideal—but it works.
There is good news, though. Plotly developers are already working on a solution. They're in the testing phase, which is where I got the idea for this answer. You can read about what Plotly's doing here.
First, I set a seed because you have random data. I used set.seed(3509). There were no changes to the data or fig.
When you hover over any point on your graph, your fill color will disappear. The tooltip does not show the trace that shouldn't be there anyway.
The fill color will return as soon as you move on or when the tooltip goes away.
This is the Javascript to call this hover event.
# the notation [12] is the curvenumber; it represnts a single trace
hoverer = "function(el, x) {
el.on('plotly_hover', function(d){
dt = {'fill': 'none'};
Plotly.restyle(el.id, dt, [12]);
});
el.on('plotly_unhover', function(d){
ft = {'fill':'tonexty'};
Plotly.restyle(el.id, ft, [12]);
});
}"
To visualize your plot with this event:
fig %>% htmlwidgets::onRender(hoverer)

Related

How do I keep the plotted graph and yaxis aligned when doing stacked subplots with plotly R

I am trying to produce a stack of plots with plotly R but the plotted lines relative to the zero axis are drifting so that what is zero in the top plot is not zero in the bottom plot. Any ideas how to fix this?
Here is an image of the problem:
Assume that the top plot is correct (it is: Gaussian random walk around zero). Then notice that in plots 2:4 from the top down the xaxis drifts upwards but the exact same data is used on all plots. Notice on the y-axis that the number 2 is drifting upwards. I feel that this is a simple issue (pretty fundamental - keeping values aligned to data!) so I think I am missing something obvious so would appreciate it if someone could point out my obvious mistake.
I have tried setting anchor and scaleanchor but this seems to have no effect on the positioning, even when position = 0 and anchor = 'free'.
I have also tried variations on fixedrange and autorange but again no joy.
Here is a reproducible example:
set.seed(2244)
cols <- c('black','red','green','cyan','blue','magenta','yellow','gray')
outlist <- list()
nplots <- c(1,2,3,4)
bounds <- 0
trials <- 0
M <- 1
N <- 50
i <- 1
y <- rnorm(N)
chleaf <- rbinom(N, 1, 0.5)
outmat <- matrix(0, nrow=N, ncol=6)
outmat[,c(1,3)] <- rnorm(dim(outmat)[1]*2, 0, 1)
outmat[,c(2,4)] <- outmat[,c(1,3)]^2
outmat[,c(5,6)] <- y - outmat[,c(1,3)]
for (j in nplots) {
mgrid <- NULL
if ( bounds == 1 ) {
mgrid <- c(min(outmat[,3]-2*sqrt(outmat[,4]))-0.5,
max(outmat[,3]+2*sqrt(outmat[,4]))+0.5)
} else {
mgrid <- c(min(min(outmat[,3]), min(outmat[,5]), min(y))-0.5,
max(max(outmat[,3]), max(outmat[,5]), max(y))+0.5)
}
outlist[[i]] <- plotly::plot_ly() %>%
plotly::add_trace(x = 1:(M*N), y = outmat[,3], type = 'scatter', mode='lines',
showlegend=ifelse(i==1, TRUE, FALSE), name=TeX('\\mu_{t|t-1}'),
line=list(color=cols[1], width=0.5)) %>%
plotly::add_trace(x = 1:(M*N), y = outmat[,3]+2*sqrt(outmat[,4]),
type='scatter', mode='markers', color=I(cols[1]), size=0.5,
showlegend=ifelse(i==1, TRUE, FALSE), name=TeX('\\Sigma_{t|t-1}'),
marker=list(symbol='cross-thin'), visible=ifelse(bounds==1, TRUE, FALSE)) %>%
plotly::add_trace(x = 1:(M*N), y = outmat[,3]-2*sqrt(outmat[,4]),
type='scatter', mode='markers', color=I(cols[1]), size=0.5,
showlegend=FALSE, marker=list(symbol='cross-thin'),
visible=ifelse(bounds==1, TRUE, FALSE)) %>%
plotly::add_trace(x = 1:(M*N), y = outmat[,1], type = 'scatter', mode='lines',
showlegend=ifelse(i==1, TRUE, FALSE), name=TeX('\\mu_{t|t}'),
line=list(color=cols[2], width=0.5)) %>%
plotly::add_trace(x = 1:(M*N), y = outmat[,1]+2*sqrt(outmat[,2]),
type='scatter', mode='markers', color=I(cols[2]), size=0.5,
showlegend=ifelse(i==1, TRUE, FALSE), name=TeX('\\Sigma_{t|t}'),
marker=list(symbol='cross-thin'), visible=ifelse(bounds==1, TRUE, FALSE)) %>%
plotly::add_trace(x = 1:(M*N), y = outmat[,1]-2*sqrt(outmat[,2]),
type='scatter', mode='markers', color=I(cols[2]), size=I(5),
showlegend=FALSE, marker=list(symbol='cross-thin'),
visible=ifelse(bounds==1, TRUE, FALSE)) %>%
plotly::add_trace(x = 1:(M*N), y = outmat[,5], type = 'scatter', mode='lines',
showlegend=ifelse(i==1, TRUE, FALSE), name=TeX('\\hat{y}_{t}'),
line=list(color=cols[3], width=0.5)) %>%
plotly::add_trace(x = 1:(M*N), y = outmat[,6], type = 'scatter', mode='lines',
showlegend=ifelse(i==1, TRUE, FALSE), name=TeX('\\tilde{y}_{t}'),
line=list(color=cols[4], width=0.5)) %>%
plotly::config(mathjax='cdn') %>%
plotly::layout(
xaxis=list(title=list(text='Iterations', standoff=0),
showline=T, showgrid=F, range = c(0, ifelse(N==1, M+0.25, N*M+0.5)),
anchor='y', scaleanchor='x'),
yaxis=list(showline=T, showgrid=F, range=mgrid))
rMe <- 0
for (n in 1:N) {
rMe <- rMe+M
nchleaf <- (M*(n-1)+1):(n*M)*chleaf[(M*(n-1)+1):(n*M)]
xupdates <- nchleaf[which(nchleaf!=0)]
yupdates <- as.vector(sapply(y[n], function(x){rep(x,length(xupdates))}))
outlist[[i]] <- outlist[[i]] %>%
plotly::add_trace(x = c(M*(n-1), n*M), y = c(y[n], y[n]),
type = 'scatter', mode='lines',
showlegend=ifelse((i==1 && n==1), TRUE, FALSE), name='y',
line=list(color = cols[6], dash = ifelse(M==1, 'solid', 'dash'),
width=0.5)) %>%
plotly::add_trace(x = xupdates, y = yupdates,
type='scatter', mode='markers',
showlegend=ifelse((i==2&&n==1), TRUE, FALSE), name='Update',
color=I(cols[5]), size=0.5) %>%
plotly::add_trace(x = rMe, y = mgrid,
type = 'scatter', mode='lines', visible=ifelse(trials==1, TRUE, FALSE),
showlegend=ifelse((trials==1 && i==1 && n==1), TRUE, FALSE), name='Trial',
line=list(color = cols[8], dash = 'dash', width=0.5))
}
i <- i+1
}
fig <- plotly::subplot(outlist, nrows=length(nplots), shareX=TRUE,
which_layout=c(1)) %>%
plotly::config(staticPlot=T, mathjax='cdn', displayModeBar = F)
fig <- fig %>% plotly::layout(
showlegend=TRUE,
legend=list(itemsizing='trace', orientation='h', xanchor='center', x=0.5),
margin=list(b=70, l=45, r=30, t=80),
title=list(text="Test Title"))
# yaxis=list(autorange=TRUE, fixedrange=FALSE))
# xaxis=list(anchor='y', scaleanchor='x'),
# yaxis=list(anchor='x', scaleanchor='y'))
# yaxis=list(range=mgrid))#,
# xaxis=list(title=list(text='Iterations', standoff=0),
# showline=T, showgrid=F, range = c(0, ifelse(N==1, M+0.25, N*M+2))),
# yaxis=list(showline=T, showgrid=F))
Its a bug in the backend of the graphics device ( or similar) . if you touch the scale knob in the export window the scales jump to the right position.
This is a workaround, i think plotly is not the ideal choice for static images since it translates to python using reticulate and its also more focused on dynamic web stuff. So i would not expect a quick bugfix.

Adding a static element across slider steps in a R plotly graph

I am giving a tutorial on MLE and am trying to figure out how to add a static grouping of points to a plotly graph. Obviously the idea is that as I slide the normal distributions over you can see that the points correspond to a lower or higher likeihood. However, I can only get the points to appear on the first frame.
x <- seq(0, 10, length.out = 1000)
aval <- list()
for (step in 1:6) {
aval[[step]] <- list(
visible = FALSE,
name = paste0('v = ', step),
x = x,
y = dnorm(x, step+1)
)
}
aval[3][[1]]$visible = TRUE
steps <- list()
fig <- plot_ly()
for (i in 1:6) {
fig <-
add_lines(
fig,
x = aval[i][[1]]$x,
y = aval[i][[1]]$y,
visible = aval[i][[1]]$visible,
name = aval[i][[1]]$name,
type = 'scatter',
mode = 'lines',
hoverinfo = 'name',
line = list(color = '00CED1'),
showlegend = FALSE
)
step <- list(args = list('visible', rep(FALSE, length(aval))),method = 'restyle')
step$args[[2]][i] = TRUE
steps[[i]] = step
}
fig <- fig %>% add_markers(x = c(4.5,5,5.5), y = c(0,0,0))
# add slider control to plot
fig <- fig %>%
layout(sliders = list(list(
active = 0,
currentvalue = list(prefix = "Frequency: "),
steps = steps
)))
fig
Why don't you use plotly's animation capabilities?
But regardless of whether you define custom steps or you use the frame parameter, you'll have to provide the "static" points for each step:
library(plotly)
library(data.table)
f <- 1:6
x <- seq(0, 10, length.out = 1000)
y <- unlist(lapply(f+1, dnorm, x = x))
DT <- CJ(f, x) # like expand.grid()
DT[, y := y]
DT[, step := paste0("step-", f)]
staticDT <- CJ(f, x = c(4.5,5,5.5), y = 0)
staticDT[, step := paste0("step-", f)]
fig <- plot_ly(
data = DT,
x = ~x,
y = ~y,
frame = ~step,
type = 'scatter',
mode = 'lines',
showlegend = FALSE,
color = I('#00CED1')
)
fig <- add_trace(
fig,
data = staticDT,
x = ~x,
y = ~y,
frame = ~step,
type = 'scatter',
mode = 'markers',
showlegend = FALSE,
color = I('red'),
inherit = FALSE
)
fig <- animation_opts(
fig, transition = 0, redraw = FALSE
)
fig <- animation_slider(
fig, currentvalue = list(prefix = "Frequency: ")
)
fig

How can I add a subcategory to axis in Plotly with R?

I am trying to add a second category to x axis with Plotly under R like this:
Here is my code:
library(plotly)
data <- data.frame(day= c(1:4),
visit = c("visit1","visit1", "visit2", "visit2"),
val = c(1:4),
flag = c("","","", 1))
fig <- plot_ly(data= data, x = ~day) %>%
add_trace(y = ~val,
type = 'scatter',
mode = 'lines+markers',
line = list(width = 2,
dash = 'solid')) %>%
add_trace(data= data %>% filter(flag == 1), y = 0,
type = 'scatter',
hoverinfo = "text",
mode = 'markers',
name = "flag",
text = paste("<br>N°",data$ID[data$flag == 1],
"<br>Day",data$day[data$flag == 1]),
marker = list(
color = 'red',
symbol = "x",
size = 12
),
showlegend = T
)
fig
I have tried this, which seems good but the markers disappear from the graph, maybe due to the filter on data.
library(plotly)
data <- data.frame(day= c(1:4),
visit = c("visit1","visit1", "visit2", "visit2"),
val = c(1:4),
flag = c("","","", 1))
fig <- plot_ly(data= data, x = ~list(visit,day)) %>%
add_trace(y = ~val,
type = 'scatter',
mode = 'lines+markers',
line = list(width = 2,
dash = 'solid')) %>%
add_trace(data= data %>% filter(flag == 1), y = 0,
type = 'scatter',
hoverinfo = "text",
mode = 'markers',
name = "flag",
text = paste("<br>N°",data$ID[data$flag == 1],
"<br>Day",data$day[data$flag == 1]),
marker = list(
color = 'red',
symbol = "x",
size = 12
),
showlegend = T
)
fig
You didn't provide a reproducible question, so I've made data. (Well, data I shamelessly stole from here). This creates a bar graph with two sets of x-axis labels. One for each set of bars. One for each group of bars. The content of the x-axis is the same in both traces.
library(plotly)
fig <- plot_ly() %>%
add_bars(x = list(rep(c("first", "second"), each = 2),
rep(LETTERS[1:2], 2)),
y = c(2, 5, 2, 6),
name = "Adults") %>%
add_bars(x = list(rep(c("first", "second"), each = 2),
rep(LETTERS[1:2], 2)),
y = c(1, 4, 3, 6),
name = "Children")
fig
Update
You added data and code trying to apply this to your data. I added an update and apparently missed what the problem was. Sorry about that.
Now that I'm paying attention (let's hope, right?), here is an actual fix to the actual problem.
For this change, I modified your data. Instead of the flag annotated with a one, I changed it to zero. Then I used flag as a variable.
data <- data.frame(day = c(1:4),
visit = c("visit1","visit1", "visit2", "visit2"),
val = c(1:4),
flag = c("","","", 0))
fig <- plot_ly(data= data, x = ~list(visit,day)) %>%
add_trace(y = ~val,
type = 'scatter', mode = 'lines+markers',
line = list(width = 2,
dash = 'solid')) %>%
add_trace(y = ~flag,
type = 'scatter', hoverinfo = "text",
mode = 'markers', name = "flag",
text = paste("<br>N°",data$ID[data$flag == 1],
"<br>Day",data$day[data$flag == 1]),
marker = list(
color = 'red', symbol = "x", size = 12),
showlegend = T)
fig
You're going to get a warning about discrete & non-discrete data, which isn't really accurate, but it shows up, nonetheless.

Choropleth world map - convert k thousand numbers

When hovering over a country the numbers are shown as say 125.115k - I want to show it as 125,115
I tried using library(formattable) and something along the lines of z = comma(worldmap$Deaths,digits = 1)
My code is below
output$World_Map <- renderPlotly({
g <- list(
showframe = FALSE,
showcoastlines = FALSE,
projection = list(type = 'Mercator')
)
plot_ly(
worldmap,
type = 'choropleth',
locations = worldmap$COUNTRY_ALPHA_3_CODE,
z = worldmap$Deaths,
text = paste("Number of Deaths: ",worldmap$COUNTRY_SHORT_NAME,"\n",comma(worldmap$Cases, digits = 0),"\n","Number of Cases: ",worldmap$COUNTRY_SHORT_NAME),
colorscale = "Reds"
) %>% layout(title = "<b>Covid19 Global Pandemic .... Data Source: <a href='https://coronavirus.jhu.edu/'>Johns Hopkins University of Medicine</a><b>", geo = g)
})
For comma rendering numbers, I use prettyNum from base R, also comma function is available in scales package.
number_a <- 123456
prettyNum(number_a, big.mark = ",")
[1] "123,456"
Your question is about text tooltip in Plotly. You can do something like this, with hoverinfo/hovertemplate and text parameters.
Of course there are other manners to do it.
Because I don't have your data, I use an example from plotly website.
library(plotly)
# code for example
# https://plotly.com/r/choropleth-maps/#using-builtin-country-and-state-geometries
# doc for hovertemplate
# https://plotly-r.com/controlling-tooltips.html#tooltip-text
df <- read.csv('https://raw.githubusercontent.com/plotly/datasets/master/2014_world_gdp_with_codes.csv')
# light grey boundaries
l <- list(color = toRGB("grey"), width = 0.5)
# specify map projection/options
g <- list(
showframe = FALSE,
showcoastlines = FALSE,
projection = list(type = 'Mercator')
)
fig <- plot_geo(df)
fig <- fig %>% add_trace(
z = ~GDP..BILLIONS., color = ~GDP..BILLIONS., colors = 'Blues',
locations = ~CODE, marker = list(line = l),
hoverinfo = "text",
text = ~glue::glue("{COUNTRY} <b>{CODE}</b>"),
hovertemplate = "%{z:,0f}<extra>%{text}</extra>"
)
fig <- fig %>% colorbar(title = 'GDP Billions US$', tickformat = ",0f")
fig <- fig %>% layout(
title = '2014 Global GDP<br>Source:CIA World Factbook',
geo = g
)
fig
With this you can easily configure your hover info / tooltip.
See here for more examples :
https://plotly.com/r/choropleth-maps/#customize-choropleth-chart
For French number (space instead of comma), you can at the end config locale:
fig %>%
config(locale = 'fr')

mapping color over variables using Restyle Buttons of plotly using R

I am trying to map color over two variables using Restyle Buttons of plotly keeping the y and x-axis dynamics when changing the colours. When I add color=~fruit in the main plot it gives the result I am looking for, but I lose the dynamics of the axes when changing the variables. I basically want to change the color of the lines referent to the fruits. Below are data and the code I am using for playing with that. Thanks for any help or hints!
libraries
library(dplyr); library(plotly);
data
dfake <- tibble(days = seq(1,100, by=1),
bask = seq(1,500, by=5),
fruit = c(rep("grape", 50),
rep("apple", 50)));
plotting code
plot <- dfake %>%
plot_ly(x = ~days, y = ~bask, text = ~fruit,
type = 'scatter',
mode = 'lines',
hoverinfo = 'text',
transforms = list(
list(type = 'filter',
target = ~fruit,
operation = '=',
value = unique(dfake$fruit)[1]))) %>%
layout(updatemenus = list(
list(type = 'dropdown',
active = 1,
buttons = list(
list(method = "restyle",
args = list("transforms[0].value",
unique(dfake$fruit)[1]),
label = unique(dfake$fruit)[1]),
list(method = "restyle",
args = list("transforms[0].value",
unique(dfake$fruit)[2]),
label = unique(dfake$fruit)[2])))));
plot;
Yes, wasn't sure of the data was in the best possible format. So, I was fiddling with this in the following manner:
Make a dataframe, where each Y-axis variable goes into individual column (refer to the tidyverse philosopy).
Appending the lines layer-by-layer into plotly.
Using updatemenus to get the interactive buttons & desired visibility.
#Converting into a dataframe, mutating new columns for each fruit and getting their name:
df_dfake <- as.data.frame(dfake)
df_dfake <- df_dfake %>% mutate(fruit1_bask = case_when(fruit == "grape" ~ bask),
fruit2_bask = case_when(fruit == "apple" ~ bask))
fruit1 <- unique(dfake$fruit)[1]; fruit2 <- unique(dfake$fruit)[2];
#Plotly, adding layer by layer:
fig <- df_dfake %>% plot_ly(type = 'scatter',
mode = 'lines',
hoverinfo = 'text');
fig1 <- fig %>% add_lines(x = ~days , y = ~fruit1_bask, text = ~fruit,
line=list(color="#33CFA5"));
fig2 <- fig1 %>% add_lines(x = ~days, y = ~fruit2_bask, text = ~fruit,
line=list(color="#F06A6A"));
fig2;
fig2
Now, updatemenus component, to make the interactive buttons
updatemenus <- list(
list(
active = -1,
type= 'buttons',
buttons = list(
list(
label = unique(dfake$fruit)[1],
method = "update",
args = list(list(visible = c(FALSE, TRUE)),# this defines visibility on click
list(title = "fruit1",
annotations = list(c(), df_dfake$fruit1_bask)))),
list(
label = unique(dfake$fruit)[2],
method = "update",
args = list(list(visible = c(T, F)),# this defines visibility on click
list(title = "fruit2",
annotations = list(c(), df_dfake$fruit2_bask))))
)
)
)
fig3 <- fig2 %>% layout(title = "Apples & Oranges", showlegend=FALSE,
xaxis=list(title="Days"),
yaxis=list(title="Basket"),
updatemenus=updatemenus); fig
Which results in the following graphs with interactive buttons:
fig3
Check Update Button to learn more :)
I finally got what I was looking for,
very easy actually, I just needed to have my grape and apple not inside column fruit but as different columns and treat them with add_trace. Setting one as invisible. In each add_trace I was free to play with color, width etc.
After this organisation it was easier to work with button .
I hope this simple coding can help someone. If not sorry.
dfake <- tibble(days = seq(1,100, by=1),
grape = seq(1,500, by=5),
apple = seq(501,1000, by=5))
fig <- plot_ly(dfake, x = ~days) %>%
add_trace(y = ~grape, name = 'Bask',
mode = 'lines+markers', type = "scatter",
marker = list(color = 'blue'),
line = list(color = 'blue', width = 4)) %>%
add_trace(y = ~apple, name = 'New', visible = F,
mode = 'lines+markers', type = "scatter",
marker = list(color = 'red'),
line = list(color = 'red', width = 4)) %>%
layout(
title = "Corona global Cases and Depths",
xaxis = list(domain = c(0.1)),
yaxis = list(title = "yaxis"),
updatemenus = list(
list(y = 0.9,
buttons = list(
list(method = "restyle",
args = list("visible", list(TRUE, FALSE)),
label = "Grape"),
list(method = "restyle",
args = list("visible", list(FALSE, TRUE)),
label = "Apple")))))
fig

Resources