You're welcome, here's how I would do it:
library(plotly)
library(purrr)
library(dplyr)
# map qsec to circle area (between 5 to 20 pixels)
mtcars <- mtcars %>%
mutate(size = scales::rescale(sqrt(qsec), to = c(5, 20)))
# creates a list of 32 circle shapes (one for each row/car)
circles <- pmap(
mtcars[c("mpg", "wt", "size")],
function(mpg, wt, size) {
list(
type = "circle",
xanchor = mpg,
yanchor = wt,
x0 = -size/2,
y0 = -size/2,
x1 = size/2,
y1 = size/2,
xsizemode = "pixel",
ysizemode = "pixel",
# other visual properties
fillcolor = "red",
line = list(color = "transparent"),
layer = "below"
)
}
)
plot_ly(mtcars, color = I("black")) %>%
add_markers(x = ~mpg, y = ~wt, text = ~qsec, marker = list(size = 3)) %>%
layout(shapes = circles) %>%
config(edits = list(shapePosition = TRUE))