1

I'm trying to plot a line chart of dt vs myvalue using Plotly in R. dt is a timestamp, and myvalue is an integer. However, I keep getting the error Error: C stack usage 15925408 is too close to the limit. In my test, I am only plotting 3 rows of the original dataframe which is basically nothing. So how can I fix this error?

library(plotly)

df = head(originalDf, 3)
dt = strptime(df$dt, "%Y-%m-%dT%H:%M:%OSZ")
myvalue = df$myvalue
plot_ly(df, x = dt, y = myvalue, type = 'scatter', mode = 'lines')
Simon Rex
  • 143
  • 2
  • 10
  • Have you tried restarting R? It sounds like you may have overwritten a function that is causing an infinite recursive loop. It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input that can be used to test and verify possible solutions. – MrFlick Sep 07 '21 at 07:34

1 Answers1

0

Late reply, but I just had a similar situation and maybe this will help someone else. I was also making a line chart with very similar arguments to your plot_ly(), and receiving the same error. I couldn't make sense of it, the data itself was fine, I hadn't overwritten any functions as some other answers suggested...

What turned out to be the key was my use of the group_by() and summarise() functions beforehand. I grouped my data according to months, and wanted the plot to display time on the x axis. However, plotly has special considerations for grouped data - from what I understand, it tries to make a separate trace for each group level. The exact combination of grouping and x-axis variable made this task apparently crash R.

Solution

The solution was simple: just stick a .groups = "drop" at the end of summarise() (or use ungroup() at some point before handing the data to the plot.) This will eliminate any leftover groupings, and make Plotly behave as expected.

The biggest issue is that the error message was in no way indicative at what point things were going wrong.

M K
  • 3
  • 3