[R plotly显示在x轴x坐标
问题描述:
我试图创建一个类似的x轴格式的图形,以这个(从https://plot.ly/r/line-charts/):给[R plotly显示在x轴x坐标
代码:
library(plotly)
x <- c(1:100)
random_y <- rnorm(100, mean = 0)
data <- data.frame(x, random_y)
p <- plot_ly(data, x = ~x, y = ~random_y, type = 'scatter', mode = 'lines')
但是,在我的机器上运行代码生成此图表:
请注意,x坐标悬停不存在。
[R版本:3.4.1 Plotly版本:4.7.1
改变plot_ly
的hoverinfo
和text
标签只是改变了图中的hoverinfo。如何在第一个图中显示相同的悬停x坐标?
更新:设置hoverinfo = "text+x"
和layout(hovermode = "x")
显示了x轴上的x坐标和点工具提示。
答
尝试设置hovermode
到'x'
p <- plot_ly(data, x = ~x, y = ~random_y, type = 'scatter', mode = 'lines') %>% layout(hovermode = 'x')
,它应该工作。
稍微玩了一下后,似乎'hovermode'显示图上所有的点都有相同的x坐标,但是并没有显示x轴上的实际x坐标(如第一张图所示)。它可能是一个版本问题? – Brydenr
奇怪...我有完全相同的版本。你在哪个操作系统上? –
MacOS Sierra:10.12.6。 – Brydenr