• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: R: How to modify the legend in plotly?

Resolved: R: How to modify the legend in plotly?

0
By Isaac Tonny on 18/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I have 3 numerical variables and plotting them via barchart in plot_ly. ‘sale’ and ‘share’ columns are visualized via bars, while ‘cost’ by red line. Now I want to customize legend a bit and add black border around cost in legend map (see expected outcome)
output:
enter image description here
Expected output: enter image description here

Answer:

This one was tricky! I know that Plotly doesn’t have anything built-in to do this simply. I tried to work out using shapes to draw this box, but that doesn’t work, because it puts the legend on top (so most of the box is hidden). I’m apparently more stubborn than Plotly though.
This answer requires the package htmlwidgets. I didn’t change your plot other an assigning it to an object. I named your Plotly object pL for this answer.
The content for the onRender function:
Call the plot and add the onRender function to draw the box.
enter image description here
By the way, this should scale with your plot, as well.

If you have better answer, please add a comment about this, thank you!

data-visualization ggplot2 plotly r tidyverse
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: Kivy widget hierarchy not behaving as expected

24/03/2023

Resolved: Pandas Groupby Get Values from Previous Group

24/03/2023

Resolved: Can’t access static methods from outside until JavaScript’s static block is over?

24/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.