2

I'm receiving the following error when running my code:

plot_ly(data, x = ~RighttoWork_NonRtw, 
              y = ~market_value_level_unfunded_liability, 
              text = ~paste("State: ", state,
                            "Market Value Level Unfunded Liability", market_value_level_unfunded_liability),  
              color = ~market_value_level_unfunded_liability,  
              size = ~market_value_level_unfunded_liability, 
              type = "scatter")

No scatter mode specifed: Setting the mode to markers Read more about this attribute -> https://plot.ly/r/reference/#scatter-mode Error: size/width values must be numeric .

Why is this the case?

I'm trying to get a series of plot points with different sized points based on the unfunded liability variable figures. Unfortunately, I keep getting this error message.

1 Answer 1

7

It's hard to answer without a reproducible example. First off you can specify the mode. Then you could try specifying the markers. Here I used your code for an example on mtcars dataset. The size of the markers is scaled by 3 here because some times the size argument of plotly can't make sense of certain values.

This aside, your error is due to the fact that market_value_level_unfunded_liability, your y variable, seems not to be numeric. You should convert it to numeric in a sensible way (use as.numeric(as.character()) if factor with numeric levels).

library(plotly)
data <- mtcars

plot_ly(data, x = ~mpg, 
        y = ~qsec, 
        text = ~paste("State: ", carb,
                      "Market Value Level Unfunded Liability", qsec),  
        color = ~qsec,  
        size = ~qsec,
        type   = 'scatter', 
        mode   = 'markers',
        marker = list(size = ~qsec*3)
        )

enter image description here

1
  • 1
    adding type = 'scatter', mode = 'markers' only helped me. Jul 10, 2020 at 16:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.