如何在使用 R(包:plotly)的绘图中查看我用 "size = " 指定的变量的值
How can I see the values of a variable that I specified with "size = " in a plotly plot using R (package: plotly)
我想使用 R 中的 plotly 包生成一个交互式图。我想要一个散点图,其中每个点都根据它们的连续值“确定大小”。我的情节确实显示了大小点,但当我将鼠标悬停在它们上面时,它并没有显示它们的值。可重现的代码:
library(plotly)
plot_ly(data = mtcars,
x = ~ wt, y = ~ mpg, color = ~factor(cyl),
mode = "markers", type = "scatter", size = ~hp)
Warning messages:
1: `line.width` does not currently support multiple values.
2: `line.width` does not currently support multiple values.
3: `line.width` does not currently support multiple values.
我想要的是当我到达一个特定点时,我想交互地查看它除了大小之外还有哪个“hp”值。
您可以将 , text = ~hp
添加到 plot_ly window 并使用 this link
格式化它
例如
library(plotly)
plot_ly(data = mtcars,
x = ~ wt, y = ~ mpg, color = ~factor(cyl),
mode = "markers", type = "scatter", size = ~hp,
text = ~hp,
hovertemplate = paste("Values: %{x}, %{y}<br>",
"Size: %{text}")
)
我想使用 R 中的 plotly 包生成一个交互式图。我想要一个散点图,其中每个点都根据它们的连续值“确定大小”。我的情节确实显示了大小点,但当我将鼠标悬停在它们上面时,它并没有显示它们的值。可重现的代码:
library(plotly)
plot_ly(data = mtcars,
x = ~ wt, y = ~ mpg, color = ~factor(cyl),
mode = "markers", type = "scatter", size = ~hp)
Warning messages:
1: `line.width` does not currently support multiple values.
2: `line.width` does not currently support multiple values.
3: `line.width` does not currently support multiple values.
我想要的是当我到达一个特定点时,我想交互地查看它除了大小之外还有哪个“hp”值。
您可以将 , text = ~hp
添加到 plot_ly window 并使用 this link
例如
library(plotly)
plot_ly(data = mtcars,
x = ~ wt, y = ~ mpg, color = ~factor(cyl),
mode = "markers", type = "scatter", size = ~hp,
text = ~hp,
hovertemplate = paste("Values: %{x}, %{y}<br>",
"Size: %{text}")
)