plotly / plotly/plotly.R

Legend "entrywidth" and "entrywidthmode" parameters appear to be ignored when knitting Rmd to HTML

Open
#2,215 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
R
Stars
2.7k
Forks
641
PR merge metrics
No merged PRs in 30d

Description

I'm trying to use plotly to plot several stacked barplots of the same size each. Each barplot has legend elements of increasing size, and I would like to set the dimensions of the legend box, instead of the legend box being the size of the longest legend element. I've found the parameters entrywidth and entrywidthmode and tried using them to set this graphic setting, but the plots look exactly the same independently on what values I use.

The data looks like this:

> head(rel_table_filtered)
                                Class Relative_frequency  Sample
3      Bacteria;Bacteria;Unclassified        0.001547047 ileum_A
4  Bacteria;Bacteria;Actinobacteriota        0.137521410 ileum_A
5      Bacteria;Bacteria;Bacteroidota        0.111055859 ileum_A
8  Bacteria;Bacteria;Desulfobacterota        0.011989613 ileum_A
9        Bacteria;Bacteria;Firmicutes        0.707497652 ileum_A
11   Bacteria;Bacteria;Proteobacteria        0.025857782 ileum_A

The function simplified function I'm using to plot the barplots is the following. Wheter I put 0.9, 0.5, 1/8, etc, on the entrywitdthmode parameter, the plot looks the same. I've also tried with autosize=FALSE and with height and width parameters on the plot_ly function, without success.

fig <- plot_ly(rel_table_filtered, type = "bar", y = ~Sample, x= ~Relative_frequency, color = ~Class, orientation = "h") %>%
    layout( barmode = 'stack', xaxis = list(title = ''), yaxis = list(title = '%'), autosize = T, legend = list(entrywidthmode = "fraction", entrywidth = 0.9), hoverlabel = list(namelength=-1) )

fig

image

I'm attaching the rel_table_filtered.csv file:
rel_table_filtered.csv

Thanks in advance!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the example using plot_ly and layout with legend entrywidth and entrywidthmode, then knit the Rmd to HTML and compare different parameter values. Check the attached rel_table_filtered.csv and the rendered legend behavior; done means these parameters visibly control the legend box dimensions in the knitted output.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data-visualization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.