我做了一个多重子图。这是我的代码:
m <- list(
#l = 50,
# r = 50,
b = 200,
#t = 100,
pad = 0
)
ma <- list(
#l = 100,
b = 100,
# t = 200,
pad = 0
)
p5<-plot_ly(moving_avg,x=~Time,y=~Moving_Average3,type="scatter" ,mode="lines",name ="Memory")%>%
add_trace(x=~Time,y = ~Moving_Average_Cpu3,mode="lines",yaxis = "y2",name ="CPU")%>%
layout(yaxis2 = list(overlaying = "y", side = "right"))%>%
layout(
title = "CPU VS MEMORY(MOVING AVERAGE)",
xaxis = list(
title = "",
zeroline=TRUE),
yaxis = list(
title = "MEMORY(%)",
zeroline=TRUE),
yaxis2 = list(
title = "CPU(%)",
zeroline=TRUE)
)%>%
layout(margin=m)
p6<-plot_ly(moving_avg,x=~Time,y=~Moving_Average3,type="scatter" ,mode="lines",name ="Memory")%>%
add_trace(x=~Time,y = ~Moving_Average_Cpu3,mode="lines",yaxis = "y2",name ="CPU")%>%
layout(yaxis2 = list(overlaying = "y", side = "right"))%>%
layout(
title = "CPU VS MEMORY(MOVING AVERAGE)",
xaxis = list(
title = "",
zeroline=TRUE),
yaxis = list(
title = "MEMORY(%)",
zeroline=TRUE),
yaxis2 = list(
title = "CPU(%)",
zeroline=TRUE)
)%>%
layout(margin=m)
subplot(p5,p6,nrows=1,which_layout = "merge", margin = 0.07,titleX = F, titleY = TRUE)%>%
layout(margin=ma)
但是你可以在图像中看到,在两个图的图表中,y轴2都被隐藏了。
我该如何解决这个问题?
答案 0 :(得分:0)
如果没有完整的数据集进行测试,您希望在https://github.com/ropensci/plotly/issues/954
处遵循msummersgill的建议它的长短: 在P6的布局下,您应该指定(而不是yaxis2 =):
yaxis4 = list(
title = "CPU(%)",
zeroline=TRUE,overlaying="y3")