我有以下代码:
library(plotly)
A <- matrix(seq(1, 365), nrow = 73, ncol = 5)
xaxis_names <- seq(from = as.Date("2001-01-01"), to = as.Date("2001-12-31"), by = 1)
p <- plot_ly(z = t(A), type = "heatmap", colorscale = "Greys") %>%
layout(xaxis = list(dtick = 1,
ticktext = xaxis_names,
tickvals = 0:length(xaxis_names)))
p
x标记标签没有以适当的方式显示。出现在绘图窗口之外,并且太多了。希望我希望它们根据我的缩放程度而动态显示,并且一次可以看到5个或10个标签。
有什么想法怎么做?
答案 0 :(得分:2)
这有帮助吗?您可以尝试将其指定为轴之一,以便plotly
可以自动找出最佳刻度间隔。
library(plotly)
A <- matrix(seq(1, 365), nrow = 73, ncol = 5)
xaxis_names <- seq(from = as.Date("2001-01-01"), to = as.Date("2001-12-31"), by = 1)
p <- plot_ly(z = t(A), x = xaxis_names, type = "heatmap", colorscale = "Greys")
p
答案 1 :(得分:1)
从@Ameya提供的解决方案开始,可以使用type="auto"
和library(plotly)
A <- matrix(seq(1, 365*5), nrow = 365, ncol = 5)
xaxis_names <- seq(from = as.Date("2001-01-01"), to = as.Date("2001-12-31"), by = 1)
p <- plot_ly(x=xaxis_names, z = t(A), type = "heatmap", colorscale = "Greys") %>%
layout(margin = list(b=100),
xaxis = list(type="auto", nticks=24, tickformat="%x", tickangle=-90))
p
指定x轴的最大刻度数:
BroadcastReceiver