在情节中设置标题

发布于 2025-02-12 14:22:34 字数 1314 浏览 1 评论 0原文

我与Plotly一起工作,我想在同一图片中放置四个图表。在下面,您可以看到数据

library(dplyr)
library(plotly)

df<-data.frame(
  Years = rep(2010:2020,len=22),
  Tax = rep(c("PIT","CIT","VAT"),22),
  Revenues = rep(c(200,400,100),22)
)



df$Pct<-prop.table(df$Revenues)


RevenueCompositionPCT <- plot_ly(df, x = ~Years, y = ~Pct,
                                 type = 'bar',
                                 marker = list(color = ~Revenues), name = ~Tax) %>%
  layout(title = "AA",
         yaxis = list(title = 'Percentage %'), barmode = 'stack')
RevenueCompositionPCT <- RevenueCompositionPCT %>% layout(legend = list(orientation = 'h'))           
RevenueCompositionPCT

现在我想在同一图片上的y轴上放置四个图表,并在y轴上放置四个图表。我尝试了以下代码,但无法正常工作。

p<-subplot(
  style(RevenueCompositionPCT, showlegend = FALSE,title=TRUE,titleY = TRUE),
  style(RevenueCompositionPCT, showlegend = FALSE,title=TRUE,titleY = TRUE),
  style(RevenueCompositionPCT, showlegend = FALSE,title=TRUE,titleY = TRUE),
  style(RevenueCompositionPCT, showlegend = TRUE,title=TRUE,titleX = TRUE, ),
  nrows =2,margin = 0.05) 
p

那么有人可以帮助我如何解决这个问题吗?

I work with Plotly and I want to put four charts in the same picture. Below you can see data

library(dplyr)
library(plotly)

df<-data.frame(
  Years = rep(2010:2020,len=22),
  Tax = rep(c("PIT","CIT","VAT"),22),
  Revenues = rep(c(200,400,100),22)
)



df$Pct<-prop.table(df$Revenues)


RevenueCompositionPCT <- plot_ly(df, x = ~Years, y = ~Pct,
                                 type = 'bar',
                                 marker = list(color = ~Revenues), name = ~Tax) %>%
  layout(title = "AA",
         yaxis = list(title = 'Percentage %'), barmode = 'stack')
RevenueCompositionPCT <- RevenueCompositionPCT %>% layout(legend = list(orientation = 'h'))           
RevenueCompositionPCT

Now I want to put four charts with separate titles and also titles on the y-axis on the same pictures. I tried with the code below but is not work properly.

p<-subplot(
  style(RevenueCompositionPCT, showlegend = FALSE,title=TRUE,titleY = TRUE),
  style(RevenueCompositionPCT, showlegend = FALSE,title=TRUE,titleY = TRUE),
  style(RevenueCompositionPCT, showlegend = FALSE,title=TRUE,titleY = TRUE),
  style(RevenueCompositionPCT, showlegend = TRUE,title=TRUE,titleX = TRUE, ),
  nrows =2,margin = 0.05) 
p

So can anybody help me how to solve this problem?

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

公布 2025-02-19 14:22:34

我认为,使用组合Widgets manipulateWidget 软件包的功能更容易:

library(manipulateWidget)
combineWidgets(p1, p2, p3, p4, nrow = 2)

其中p1,p2,p3,p3,p4是您的绘图。

I think it's easier with the combineWidgets function of the manipulateWidget package:

library(manipulateWidget)
combineWidgets(p1, p2, p3, p4, nrow = 2)

where p1, p2, p3, p4 are your plotly plots.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文