spurious warning when mapping marker size in plotly R

wib*_*ley 5 r plotly r-plotly

The simple scatterplot has a third variable mapped to the marker/point size. The plot looks perfect to me, but it throws a warning about multiple values. Each x & y value has exactly one size value.

Other than suppressing the warning, can a respecify this graph so it does not throw the warning?

Warning message:
`line.width` does not currently support multiple values.
Run Code Online (Sandbox Code Playgroud)

Code:

plotly::plot_ly(
  data  = iris, 
  x     = ~Sepal.Length, 
  y     = ~Petal.Length, 
  size  = ~Sepal.Width,
  type  = 'scatter', 
  mode  = 'markers'
)
Run Code Online (Sandbox Code Playgroud)

Graph: 散点图

Note: This may be related to Plotly R - error "`line.width` does not currently support multiple values." or Scatter mapbox in shiny R will not render, but those questions have a lot more moving pieces, so I don't know if this is their core problem.

edit: I've since posted this question at https://github.com/ropensci/plotly/issues/1367

fra*_*nky 6

我也有同样的问题。查看plotly github页面,如下所示: https: //www.reddit.com/r/RStudio/comments/9xq4gv/plotly_api_error_client_error_400_bad_request/,并搜索错误,引导我找到生成它的代码:

# if fill does not exist, `size` controls line.width
      if (!has_fill(trace) && has_attr(type, "line")) {
        s <- if (isSingular) size_ else if (array_ok(attrs$line$width)) sizes else NA
        if (is.na(s)) {
          warning("`line.width` does not currently support multiple values.", call. = 
    FALSE)
        } else {
          trace[["line"]] <- modify_list(list(width = default(s)), trace[["line"]])
        }
      }
Run Code Online (Sandbox Code Playgroud)

参数 fill 默认为“none”。将其设置为空字符串,并
sizemode = ~diameter在标记中设置对我有用:

plotly::plot_ly(
data   = iris, 
x      = ~Sepal.Length, 
y      = ~Petal.Length,
type   = 'scatter', 
mode   = 'markers',
size = ~Sepal.Width,
fill = ~'',
marker = list(sizemode = 'diameter'))
Run Code Online (Sandbox Code Playgroud)


vli*_*ana 5

我主要在 Python 中使用 Plotly,所以我不确定细节,但大小是 Plotly 中许多事物的属性。我猜测通过设置size = ~Sepal.Width该级别,库无法知道您想要设置标记大小。

plotly::plot_ly(
    data   = iris, 
    x      = ~Sepal.Length, 
    y      = ~Petal.Length,
    type   = 'scatter', 
    mode   = 'markers',
    marker = list(
        size = ~Sepal.Width*3
    )
)
Run Code Online (Sandbox Code Playgroud)

这对我有用,由于某种原因,点变小了很多,但缩放它们效果很好。