Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to give subtitles for subplot in plot_ly using R

Tags:

I am wondering how to give difference subtitles for the subplots using plot_ly. Any hint please. I got one title BB in this case. Thanks.

p <- subplot(       plot_ly(economics, x = date, y = uempmed)%>%layout(showlegend = FALSE, title="AA"),       plot_ly(economics, x = date, y = unemploy)%>%layout(showlegend = FALSE, title="BB"), margin = 0.05 )  
like image 854
yuxu zi Avatar asked May 17 '16 20:05

yuxu zi


People also ask

Does Plotly work with R?

Plotly is a free and open-source graphing library for R. We recommend you read our Getting Started guide for the latest installation or upgrade instructions, then move on to our Plotly Fundamentals tutorials or dive straight in to some Basic Charts tutorials.

What is a subplot in R?

The subplot() function Conceptually, subplot() provides a way to place a collection of plots into a table with a given number of rows and columns. The number of rows (and, by consequence, the number of columns) is specified via the nrows argument.

How do you change the subplot size in Plotly?

top - layout. margin. bottom. In such a rectangle you set the width and height of each subplot, in pixels.

How do you use subplots in Plotly?

Simple SubplotFigures with subplots are created using the make_subplots function from the plotly. subplots module. Here is an example of creating a figure that includes two scatter traces which are side-by-side since there are 2 columns and 1 row in the subplot layout.


1 Answers

The title attribute in layout refers to the title for the entire plotting surface, so there can only be one. However, we can use text annotations to create "titles" for your subplots, for example:

p <- subplot(   plot_ly(economics, x = date, y = uempmed)%>%layout(showlegend = FALSE),   plot_ly(economics, x = date, y = unemploy)%>%layout(showlegend = FALSE),   margin = 0.05 )  p %>% layout(annotations = list(  list(x = 0.2 , y = 1.05, text = "AA", showarrow = F, xref='paper', yref='paper'),   list(x = 0.8 , y = 1.05, text = "BB", showarrow = F, xref='paper', yref='paper')) ) 
like image 149
d-roy Avatar answered Sep 18 '22 06:09

d-roy