Reputation: 10372
I'm creating a simple plot with plot_ly
and come to a strange behaviour when using error bars. I have tried the example here, but even the official manual is wrong (in my opinion). Here an MWE:
library(plotly)
df <- data.frame(
x = 1:3,
y = c(7,5,9),
sd = c(0.2, 0.1, 0.7))
plot_ly(df,
x = ~x,
error_y = list(value = ~sd)) %>%
add_markers(y = ~y)
The result is not the expected plot, because the errorbars are always 10% of the value, even in the official examples (see link above). It's obvious that the errorbar are much higher than the given ones in df
. The error are always 10 % of the original value.
I tried different approaches, e.g. error_y = list(value = ~sd, type = "data"))
(seen here), but nothing worked.
I'm thankful for every hint to solve this issue.
Upvotes: 1
Views: 4277
Reputation: 31709
It seems that the Plotly team has forgotten to update its own examples. The correct syntax for getting error bars in R Plotly is
error_y = list(array=~sd)
library(plotly)
df <- data.frame(
x = c(1, 2, 3),
y = c(7, 5, 3),
sd = c(0.1, 0.3, 0.8))
plot_ly(df,
x = ~x,
y = ~y,
error_y = list(array=~sd),
type='scatter')
Upvotes: 3