Black Lives Matter. Please consider donating to Black Girls Code today.

Change source code for underlying calculation for box plot in R

Box plot using plotly is not returning correct values for Q25 and Q75.
I have already supplied all the quantile values in the dataframe.

Here is my code:

x <- c(94, 157, 185, 220, 239)
y <- rep(“tst”, length(x))

df <- cbind.data.frame(x, y)
quantile(x, 0.25)
library(plotly)

plot_ly(df, x = df\$y, y = df\$x, type = “box”)

I can view correct values with ggplot2 and rbokeh.

Edit:
Calculation for ‘n’ needs to be modified to:
n = n * (arr.length-1) ;

Does anybody know how to change this in the source for R?

Got the solution.

The calculation for plotly.js is present in the following path:
plotly.js/src/lib/stats.js

Calculation:
exports.interp = function(arr, n) {
if(!isNumeric(n)) throw ‘n should be a finite number’;
n = n * arr.length - 0.5;
if(n < 0) return arr[0];
if(n > arr.length - 1) return arr[arr.length - 1];
var frac = n % 1;
return frac * arr[Math.ceil(n)] + (1 - frac) * arr[Math.floor(n)];
};