13.5 气泡图
简单图形 scatter,分布图几类,其中 scatter、heatmap、scatterpolar 支持 WebGL 绘图引擎
# https://plotly.com/r/bubble-charts/
<- diamonds[, .(
dat carat = mean(carat),
price = sum(price),
cnt = .N
= .(cut)]
), by
plot_ly(
data = dat, colors = "Greys",
x = ~carat, y = ~price, color = ~cut, size = ~cnt,
type = "scatter", mode = "markers",
marker = list(
symbol = "circle", sizemode = "diameter",
line = list(width = 2, color = "#FFFFFF"), opacity = 0.4
),text = ~ paste(
sep = " ", "重量:", round(carat, 2), "克拉",
"<br>价格:", round(price / 10^6, 2), "百万"
),hoverinfo = 'text'
%>%
) add_annotations(
x = ~carat, y = ~price, text = ~cnt,
showarrow = F, font = list(family = "sans")
%>%
) layout(
xaxis = list(hoverformat = ".2f"),
yaxis = list(hoverformat = ".0f")
)