How to add significance stars to a Plotly boxplot

Hi all, I have the following boxplot that I made with Plotly, and I was wondering if there was a general way of adding the significance asterisks above them? I have already done the statistic test, so I only have to add them by hand.

Desorder rates of TR-BRP, TR & Reference

Here’s my code:

begin
	x_data=name_bx_tr #names of the boxplots
	y_data=(dn7bx_tr_rna,dn7bx_tr, dn7bx_tr_anti) #data
	color_vec = ["rgba(93, 164, 214, 0.5)", "rgba(255, 144, 14, 0.5)", "rgba(207, 114, 255, 0.5)"]


	traces = [
    	box(
        	y=yd,
        	name=xd,
        	boxpoints="all",
        	jitter=0.5,
        	whiskerwidth=0.2,
        	fillcolor=cls,
        	marker_size=2,
        	line_width=1,

    	)
    	for (xd, yd, cls) in zip(x_data, y_data, color_vec)
	]

	layout = Layout(
    	title="Evolutionary rates of RBP-TR, TR and Reference proteins",
    	yaxis=attr(
        	autorange=true,
        	showgrid=true,
        	zerline=true,
        	dtick=5,
        	gridcolor="rgb(255,255,255)",
        	zerlinecolor="rgb(255,255,255)",
        	zerolinewidth=2
    	),
    	margin=attr(
        	l=40,
        	r=30,
        	b=80,
        	t=100
    	),
    	paper_bgcolor="rgb(243,243,243)",
    	plot_bgcolor="rgb(243,243,243)",
    	showlegend=false,
		height=400
	)

	Plot(traces, layout)
end

I supuse it goes somewhere on layout, but it is not documented at all in their page.

Thanks a lot!

1 Like

There is no general (ie smart/automatic) way to add significance asterisks or brackets in Plotly. Use shapes for brackets and annotations for asterisks/daggers/etc.

This helper function I wrote previously for making the bracket shape may be of use to you:

function bracket(xcent, width, y, yoffset, legheight; yref="y")
    path("""
            M $(xcent - width/2) $(y + yoffset - legheight)
            V $(y + yoffset)
            H $(xcent + width/2)
            V $(y + yoffset - legheight)
        """; xref="paper", yref=yref, line_width=1.5)
end

Thanks! I am not sure how to use the function yet, could you provide a simple example if it is not too much trouble?

Ops, I already figured it out, just needed a little more time. Plotly is kinda new for me. Thanks a lot!!

1 Like