r plotly - 如何防止悬停名称被截断
r plotly - how to prevent hover name being truncated
由于名称过长,出现在我的情节中悬停框外的悬停名称被截断了。我找到了 plotly.js and plotly.py 但不是 R 的解决方案。我已经能够从悬停中删除该名称或将其移动到具有值的框中,但需要一个解决方案来保持它的位置,同时允许整个名称可见。
# sample data
Value <- rnorm(100, mean = 5)
Time <- c(1:100)
Site <- "Really long name for Site 1"
datTemp <- data.frame(Time, Value, Site)
Value <- rnorm(100, mean = 5)
Time <- c(1:100)
Site <- "Really long name for Site 2"
datTemp2 <- data.frame(Time, Value, Site)
Value <- rnorm(100, mean = 5)
Time <- c(1:100)
Site <- "Really long name for Site 3"
datTemp3 <- data.frame(Time, Value, Site)
figTemp<-datTemp%>%
plot_ly(x = ~Time, y = ~Value, type = "scatter", mode = "lines", line = list(width = 0.75), name = ~Site[1])%>%
layout(xaxis = list(title = "Date"), yaxis = list(title = "Temperature (C)"), legend = list(x = 0, y = 1.05, orientation = "h"))
figTemp<-figTemp%>%
add_trace(data = datTemp2, y = ~Value, type = "scatter", mode = "lines", name = ~Site[1])%>%
add_trace(data = datTemp3, y = ~Value, type = "scatter", mode = "lines", name = ~Site[1])
将 hovertemplate = paste('(%{x}, %{y})')
添加到您对 plot_ly
的呼叫中。工作了。试试这个:
library(tidyverse)
library(plotly)
# sample data
Value <- rnorm(100, mean = 5)
Time <- c(1:100)
Site <- "Really long name for Site 1"
datTemp <- data.frame(Time, Value, Site)
Value <- rnorm(100, mean = 5)
Time <- c(1:100)
Site <- "Really long name for Site 2"
datTemp2 <- data.frame(Time, Value, Site)
Value <- rnorm(100, mean = 5)
Time <- c(1:100)
Site <- "Really long name for Site 3"
datTemp3 <- data.frame(Time, Value, Site)
figTemp<-datTemp%>%
plot_ly(x = ~Time, y = ~Value, type = "scatter", mode = "lines", line = list(width = 0.75), name = ~Site[1],
hovertemplate = paste('(%{x}, %{y})')) %>%
layout(xaxis = list(title = "Date"), yaxis = list(title = "Temperature (C)"), legend = list(x = 0, y = 1.05, orientation = "h"))
figTemp<-figTemp%>%
add_trace(data = datTemp2, y = ~Value, type = "scatter", mode = "lines", name = ~Site[1]) %>%
add_trace(data = datTemp3, y = ~Value, type = "scatter", mode = "lines", name = ~Site[1])
figTemp
由 reprex package (v0.3.0)
于 2020 年 3 月 18 日创建
由于名称过长,出现在我的情节中悬停框外的悬停名称被截断了。我找到了 plotly.js and plotly.py 但不是 R 的解决方案。我已经能够从悬停中删除该名称或将其移动到具有值的框中,但需要一个解决方案来保持它的位置,同时允许整个名称可见。
# sample data
Value <- rnorm(100, mean = 5)
Time <- c(1:100)
Site <- "Really long name for Site 1"
datTemp <- data.frame(Time, Value, Site)
Value <- rnorm(100, mean = 5)
Time <- c(1:100)
Site <- "Really long name for Site 2"
datTemp2 <- data.frame(Time, Value, Site)
Value <- rnorm(100, mean = 5)
Time <- c(1:100)
Site <- "Really long name for Site 3"
datTemp3 <- data.frame(Time, Value, Site)
figTemp<-datTemp%>%
plot_ly(x = ~Time, y = ~Value, type = "scatter", mode = "lines", line = list(width = 0.75), name = ~Site[1])%>%
layout(xaxis = list(title = "Date"), yaxis = list(title = "Temperature (C)"), legend = list(x = 0, y = 1.05, orientation = "h"))
figTemp<-figTemp%>%
add_trace(data = datTemp2, y = ~Value, type = "scatter", mode = "lines", name = ~Site[1])%>%
add_trace(data = datTemp3, y = ~Value, type = "scatter", mode = "lines", name = ~Site[1])
将 hovertemplate = paste('(%{x}, %{y})')
添加到您对 plot_ly
的呼叫中。工作了。试试这个:
library(tidyverse)
library(plotly)
# sample data
Value <- rnorm(100, mean = 5)
Time <- c(1:100)
Site <- "Really long name for Site 1"
datTemp <- data.frame(Time, Value, Site)
Value <- rnorm(100, mean = 5)
Time <- c(1:100)
Site <- "Really long name for Site 2"
datTemp2 <- data.frame(Time, Value, Site)
Value <- rnorm(100, mean = 5)
Time <- c(1:100)
Site <- "Really long name for Site 3"
datTemp3 <- data.frame(Time, Value, Site)
figTemp<-datTemp%>%
plot_ly(x = ~Time, y = ~Value, type = "scatter", mode = "lines", line = list(width = 0.75), name = ~Site[1],
hovertemplate = paste('(%{x}, %{y})')) %>%
layout(xaxis = list(title = "Date"), yaxis = list(title = "Temperature (C)"), legend = list(x = 0, y = 1.05, orientation = "h"))
figTemp<-figTemp%>%
add_trace(data = datTemp2, y = ~Value, type = "scatter", mode = "lines", name = ~Site[1]) %>%
add_trace(data = datTemp3, y = ~Value, type = "scatter", mode = "lines", name = ~Site[1])
figTemp
由 reprex package (v0.3.0)
于 2020 年 3 月 18 日创建