如何在顶部的R绘图子图中移动xaxis?

时间:2018-09-20 12:22:48

标签: r plotly subplot

我有多个使用子图组合的图。我想将x轴的右波纹管标题放在顶部。

这就是我所做的-

dt <- data.frame(xaxis = c("AA", "BB", "CC", "DD", "EE"),
                 Col1 = runif(5,min = 0,max = 10),
                 Col2 = runif(5,min = 0,max = 10),
                 Col3 = runif(5,min = 0,max = 10),
                 Col4 = runif(5,min = 0,max = 10),
                 Col5 = runif(5,min = 0,max = 10),
                 Col6 = runif(5,min = 0,max = 10),
                 Col7 = runif(5,min = 0,max = 10),
                 Col8 = runif(5,min = 0,max = 10),
                 Col9 = runif(5,min = 0,max = 10),
                 Col10 = runif(5,min = 0,max = 10))



plot_func <- function(dt){
  col_names <- colnames(dt)[-(1:8)]
 lapply(col_names,function(x){
   plot_ly( x = dt$xaxis, y = dt[,x], type = 'scatter', mode = 'lines')%>%
           layout(yaxis = list(title = x),xaxis = list(title = "Date",
                                                       side = "top")
           )
    }
  )
}


subplot(plot_func(dt),
        nrows = NROW(colnames(dt)[-(1:8)]),margin = 0.05,shareX = TRUE,
       titleY = TRUE,titleX = TRUE)%>%
layout(showlegend = FALSE,title = "ABC")

1 个答案:

答案 0 :(得分:1)

子图块上的微小变化就可以做到...

https://db.example.com:2083/logout