是否有R plot_ly子图函数可以设置子图标题的文本大小?

toe95027  于 2023-03-10  发布在  其他
关注(0)|答案(1)|浏览(114)

我正在尝试使用plot_ly subplot更改子图标题文本的大小。
我目前使用的代码如下:

subplot(unemployed, employed, not_in_labor_force, 
        nrows = 3,
        titleY = TRUE, titleX = TRUE, shareX = TRUE) %>%
        layout(title = "Employment, Unemployment, and Not in Labor Force Shares by Race",
               yaxis = list(zerolinewidth = 2, 
                            zerolinecolor = '#ffff',
                            titlefont = list(size = 8)))

Image of the Current Output
如您所见,只有第一个子图的标题响应size = 8函数。
如何更改其他标题?
我试着在每个plot_ly对象中设置标题大小,我也试着使用titlefont2 = ......两者都抛出了错误,而不是改变子情节输出。

8yparm6h

8yparm6h1#

由于你的代码是不可复制的,我使用这个例子。
可按如下方式设置每个图的y轴字体大小:

# Warning messages:
#   1: The titlefont attribute is deprecated. Use title = list(font = ...) instead.

library(plotly) 
fig1 <- plot_ly(x = c(3, 4, 5), y = c(1000, 1100, 1200), type = 'scatter', mode = 'lines+markers') |> layout(yaxis = list(title = list(text = 'Title A', font = list(size = 8)))) 
fig2 <- plot_ly(x = c(2, 3, 4), y = c(100, 110, 120), type = 'scatter', mode = 'lines+markers') |> layout(yaxis = list(title = list(text = 'Title B', font = list(size = 8)))) 
fig3 <- plot_ly(x = c(0, 1, 2), y = c(10, 11, 12), type = 'scatter', mode = 'lines+markers') |> layout(yaxis = list(title = list(text = 'Title C', font = list(size = 8)))) 
fig <- subplot(fig1, fig2, fig3, nrows = 3, titleY = TRUE, titleX = TRUE, shareX = TRUE, which_layout = "merge") %>% 
  layout(title = list(text = "Stacked Subplots"),
         plot_bgcolor='#e5ecf6', 
         xaxis = list( 
           zerolinecolor = '#ffff', 
           zerolinewidth = 2, 
           gridcolor = 'ffff'), 
         yaxis = list( 
           zerolinecolor = '#ffff', 
           zerolinewidth = 2, 
           gridcolor = 'ffff')) 
fig

相关问题