Please see my question in stackoverflow
I have an array of values from 0-10 with and 20 groups in each. For some groups or categories all values are 0. When I use violin plot, there is an area calculated which is below 0, but I want to get thedifferent that I got from Seurat package VlnPlot. Is there a way to overcome that problem? Here is a part of java script code:
var my_violin = [];
var vln_layout = {};
var my_violin =[
{
type:"violin",
x:xvalues,
y:my_categories,
points:"all",
pointpos:0,
color:"black",
width:0.75,
marker:{color:"black",size:4},
jitter:1,
span:0,
transforms:[
{
type:"groupby",
groups:my_categories,
styles:my_styles
}
]
}
]
var vln_layout = {title: "my title", xaxis:{showline: false,showgrid: false,zeroline: false,
categoryorder: 'category ascending'}, yaxis: {showline: false,showgrid: false,zeroline:false},
showlegend:true,legend:{traceorder:'normal',categoryorder:"ascending"}};
Plotly.newPlot('myDiv2', my_violin, vln_layout, {showSendToCloud: false});
Thank you @micosacak for your interest in plotly.js and for reporting this.
When reporting an issue, it is more convenient for the maintainers if you provide a Codepen showing the problem. I prepared one here: https://codepen.io/antoinerg/pen/QoqWBb. Can you fork it and add the missing variables xvalues, my_categories and my_styles?
Thank you!
Thanks a lot @antoinerg. I forked the values as following;
xvalues and yvalues. my_categories is equal to xvalues. I changed it accordingly.
And especially, Cell_0, Cell_5, Cell_6, Cell_7 and Cell_17 have zero values for all. I also wonder why Cell_14 and Cell_16, as well with negative values.
Trying to plot datasets [0,0,0,0] (left) and [0,0,0,1] (right) with violins:


Thanks @micosacak for reporting this issue!
Even when setting spanmode to hard, the calcSpan function returns [-1, 1] even if all values are zeroes. This happens when calling dummyAx.cleanRange(); on line 155:
https://github.com/plotly/plotly.js/blob/7e68a2e56f5cfca1286163bda63b5f8263c43451/src/traces/violin/calc.js#L126-L158
I haven't delved into violin much so I am not sure what is the best way to tackle the issue at hand. Any suggestions @plotly/plotly_js ?
@alexcjohnson I'm tempted to return a tiny range around cdi.min and cdi.max when they're equal (say +/- 1E-6).
It looks fine alongside another violin:

but when displayed alone, it has an arbitrary size:

I don't think we can do that, whatever size we choose someone will come up with a data set that has a natural size smaller than that. It has to actually have zero size, even if that means a special case with its own drawing code.
@alexcjohnson I don't know what I was thinking :sweat_smile:! That would have been a horrible hack. PR #3625 is much better.
Most helpful comment
I don't think we can do that, whatever size we choose someone will come up with a data set that has a natural size smaller than that. It has to actually have zero size, even if that means a special case with its own drawing code.