How to increase size of the Plot in Plotly in R Studio IDE - Html Widget ?

Hi I created a plotly bar chart. However the result which is displayed horizontally getting cut. How can I increase the plot pane so that I can view the whole chart in a single view ?

season_grouped <- season_clean %>% 
  group_by(session_start_dow) %>% 
  summarise(session_duration = mean(session_duration)) %>% 
  arrange(factor(session_start_dow, levels = day_order))

off_season_grouped <- off_season_clean %>% 
  group_by(session_start_dow) %>% 
  summarise(session_duration = mean(session_duration)) %>% 
  arrange(factor(session_start_dow, levels = day_order))



fig <- plot_ly() %>%
  add_trace(x = season_grouped$session_start_dow, 
            y = season_grouped$session_duration, 
            name = 'Season', 
            type = 'bar', 
            marker = list(color = '#e16a60'), 
            text = round(tax_season_grouped$session_duration, 2), 
            textposition = 'inside', 
            textfont = list(size = 12)) %>%
  add_trace(x = off_season_grouped$session_start_dow, 
            y = off_season_grouped$session_duration, 
            name = 'Off Season', 
            type = 'bar', 
            marker = list(color = '#50514F'), 
            text = round(off_season_grouped$session_duration, 2), 
            textposition = 'inside', 
            textfont = list(size = 8))


fig <- fig %>% 
  layout(barmode = 'group',
         xaxis = list(title = 'Day of Week', tickangle = 0),
         yaxis = list(title = 'Average Session Duration in Minutes'),
         width = 1200,
         height = 600,
         legend = list(yanchor = "top", y = 1, xanchor = "left", x = 0.01))


# Show the plot
fig

Hi @viky1

I think you're using a Quarto / R Markdown notebook for this, is that right?

If so, what happens when you render the document - is the plotly chart fully shown then?

If not, you can add execution-options to specify dimensions in either the cell or in the document yaml.

For example, in the code chunk you can add

#```{r}
#| fig-width: 10
#| fig-height: 5

season_grouped <- season_clean %>% 
  group_by(session_start_dow) %>% 
  ... etc

#```

But bear in mind there is a limit to the width based on your output filetype - page width for PDF / Word, etc, or screen width for html.

Does this help?

Hi @craig.parylo - I am using R markdown for this. I want to initially view details in the chart and any improvements I can make within the IDE itself before rendering into HTML etc. Is there a way I can increase the plot size just within IDE first ? i tried your fig-width and height and it does not show any improvement in size of plot within the IDE .

Ex- chart showed above has friday, saturday, sunday missing and not able to see contents in the bar

Hi @viky1

Thank you for responding with the update.

Can you view the full plot by clicking the 'Show in New Window' button, as shown here?

The execution-options I mentioned apply only when your document is rendered, not in the IDE session, unfortunately.

But they are useful if you wish to specify the aspect ratio of the plot in your final document.

thanks @craig.parylo - this one can make it work for time being :slight_smile:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.