首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

` `plotly::layout()`中的` `showticklabels = FALSE`失败,出现多个子图

plotly::layout()中,showticklabels = FALSE用于控制坐标轴刻度标签的显示与隐藏。然而,当在包含多个子图的布局中使用该参数时,可能会出现无法隐藏刻度标签的情况。

解决这个问题的方法是使用plotly::subplot()函数来创建子图,并在每个子图的布局中设置xaxisyaxisshowticklabels参数为FALSE。以下是一个示例代码:

代码语言:txt
复制
library(plotly)

# 创建子图1
subplot1 <- plot_ly(data = iris, x = ~Sepal.Length, y = ~Petal.Length, type = "scatter", mode = "markers")
layout1 <- list(xaxis = list(showticklabels = FALSE), yaxis = list(showticklabels = FALSE))

# 创建子图2
subplot2 <- plot_ly(data = iris, x = ~Sepal.Width, y = ~Petal.Width, type = "scatter", mode = "markers")
layout2 <- list(xaxis = list(showticklabels = FALSE), yaxis = list(showticklabels = FALSE))

# 创建子图3
subplot3 <- plot_ly(data = iris, x = ~Sepal.Length, y = ~Petal.Width, type = "scatter", mode = "markers")
layout3 <- list(xaxis = list(showticklabels = FALSE), yaxis = list(showticklabels = FALSE))

# 创建子图4
subplot4 <- plot_ly(data = iris, x = ~Sepal.Width, y = ~Petal.Length, type = "scatter", mode = "markers")
layout4 <- list(xaxis = list(showticklabels = FALSE), yaxis = list(showticklabels = FALSE))

# 组合子图并设置整体布局
subplot <- subplot(subplot1, subplot2, subplot3, subplot4, nrows = 2, ncols = 2)
layout <- list(xaxis = list(showticklabels = FALSE), yaxis = list(showticklabels = FALSE))

# 显示图形
subplot %>% layout(layout)

在上述代码中,我们使用plotly::subplot()函数创建了四个子图,并分别设置了每个子图的布局,将showticklabels参数设置为FALSE来隐藏刻度标签。最后,使用subplot %>% layout(layout)将子图和整体布局组合起来并显示出来。

这样,你就可以成功隐藏plotly::layout()中的showticklabels参数在多个子图中的刻度标签了。

页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

没有搜到相关的合辑

领券