0

Here's the plot as generated by ggplot() enter image description here

And here it is as mashed by ggplotly()

enter image description here

How can I fix the second plot to look like the first with respect to the legend? Please ignore the differences in the font weights. They are a product of the overall size of the image and disappear when enlarged.

I tried:

layout(map, legend = list(
        y = 0.5,               # Adjust vertical position of legend
        traceorder = "normal", # Ensure the legend items are in the correct order
        tracegroupgap = 20    # Increase the height of each legend item
    ))

and

    map <- htmlwidgets::onRender(map, '
      function(el) {
        var legend = el.querySelector(".legend");
        if (legend) {
          legend.style.borderTop = "none"; // Remove the black line at the top of each color section
          var items = legend.querySelectorAll(".traces"); // Select all legend items
          if (items) {
            for (var i = 0; i < items.length; i++) {
              items[i].style.paddingTop = "10px"; // Increase the height of each legend item
            }
          }
        }
      }
    ');

and

    map <- plotly::style(map, legend = list(
        bordercolor = "transparent",  # Remove black line at top of each color section
        traceorder = "normal",        # Ensure legend items are in correct order
        tracegroupgap = 30            # Increase the height of each legend item
    ))

but none of these had any effect.

0

Browse other questions tagged or ask your own question.