在情节中设置标题
我与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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为,使用
组合Widgets
manipulateWidget 软件包的功能更容易:其中
p1,p2,p3,p3,p4
是您的绘图。I think it's easier with the
combineWidgets
function of the manipulateWidget package:where
p1, p2, p3, p4
are your plotly plots.