You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Plotly中使用add_markers函数为散点添加边框的方法

Add Border to Scatter Points with add_markers() in Plotly R

No worries, I’ve been there too! When building plots incrementally with add_markers(), you just need to nest the line parameters inside the marker argument of add_markers()—the same way you did in your original plot_ly() call. Here's how to tweak your code to get that desired border:

plot_ly(data = iris) %>% 
  add_markers(
    x = ~Sepal.Length, 
    y = ~Petal.Length, 
    marker = list(
      color = 'rgba(255, 182, 193, .9)',  # Your original fill color
      size = 10,  # Optional: match the size from your ideal implementation
      line = list(
        color = 'rgba(152, 0, 0, .8)',  # Border color
        width = 2  # Border width
      )
    )
  )

Why this works

The add_markers() function accepts a marker list parameter, just like the initial plot_ly() call. All marker-related properties (fill color, size, border line) go inside this list, keeping it consistent with how you define markers in simpler plots. This approach is perfect for complex scenarios where you’re adding multiple layers or customizing plots step-by-step.

If you ever need to map colors to a data variable instead of using a fixed color, you can still keep the line settings inside the marker list—just move the color argument outside the list (e.g., color = ~Species) and define the border properties within marker$line.

内容的提问来源于stack exchange,提问作者potockan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 08:43:05