R plotly error bars are always just a factor of 10


#1

I’m getting a peculiar error regardless of whether I use my data or the plotly example. Looking at the sample data here here:

If you look – the error bars are just the estimate value divided by 10. Not what they actually should be. For instance, running the code:

temp <- ggplot2::mpg %>% group_by(class) %>%

  • summarise(mn = mean(hwy), sd = 1.96 * sd(hwy))
    

Source: local data frame [6 x 3]

   class       mn        sd
   (chr)    (dbl)     (dbl)

1 2seater 24.80000 2.555527
2 compact 28.29787 7.411975
3 midsize 27.29268 4.186422
4 minivan 22.36364 4.042804
5 pickup 16.87879 4.457588
6 subcompact 28.14286 10.535024

You see that the SD for the subcompact should be +/- 10.53, not the number the plot shows which is 2.814.

After digging in the source code, I found that instead you need to do:
error_y = list(type = "data", array = (your values))

Then it seems to work. However, the website should be updated to show this no?


#2

Hi, thanks for pointing this out! We will update the docs accordingly.


#3

Hey I had this same exact issue, with the following code,

data_mean <- ddply(ToothGrowth, c(“supp”, “dose”), summarise, length = mean(len))
data_sd <- ddply(ToothGrowth, c(“supp”, “dose”), summarise, length = sd(len))
data <- data.frame(data_mean, data_sd$length)
data <- rename(data, c(“data_sd.length” = “sd”))
data$dose <- as.factor(data$dose)

p <- plot_ly(data = data[which(data$supp == ‘OJ’),], x = ~dose, y = ~length, type = ‘scatter’, mode = ‘lines+markers’,
name = ‘OJ’,
error_y = ~list(value = sd,
color = ‘#000000’)) %>%
add_trace(data = data[which(data$supp == ‘VC’),], name = ‘VC’)

So would you, replace the

error_y = ~list(value = sd,
color = ‘#000000’)

with your suggestion?


#4

Could you please make those changes in the official doc yankev ? I’ve been struggling to find out what was wrong with my errors bars until i found this topic. And one year passed since OP asked this…