Skip to content
Prev 387666 / 398502 Next

"for" loop does not work with my plot_ly command

Printing the return value of plot_ly and friends works for me in the
following examples:
# make base plot
p0 <- plotly::plot_ly(na.omit(palmerpenguins::penguins), x =
~bill_length_mm, y = ~body_mass_g)
# now add things to base plot
for(vrbl in list(~species, ~island, ~year)) {
   tmp <- plotly::add_markers(p0, symbol=vrbl, color=vrbl)
   print(tmp)
}
# or, the put the plots in a list
plots <- lapply(list(~species, ~island, ~year), function(vrbl)
plotly::add_markers(p0, symbol=vrbl, color=vrbl))
print(plots)



On Tue, Mar 30, 2021 at 2:26 AM Rachida El Ouaraini
<elouaraini at gmail.com> wrote: