我想要创建一个圆滑的对象,即1。在x轴和2轴上躲避的位置.)以我想要的方式格式化文本。我能够分别满足每一个条件,但不能同时做到这两个条件。
在这里,我有一个巧妙的情节,正确的位置回避。
library(tidyverse)
library(plotly)
df <- data.frame(
x = c(1, 2, 3, 4),
y = runif(8, 5, 10),
cat = c("a", "a", "a", "a", "b", "b", "b", "b")
)
p <- ggplot(df, groups = cat) +
geom_point(aes(x = x, y = y, color = cat),
position = position_dodge(width = 0.3))
ggplotly(p)这里我有一个带有格式悬停文本的情节
plot_ly(df, x = ~x,
y = ~y,
type = 'scatter',
mode = 'markers',
color = ~cat,
hoverinfo = 'text',
text = ~paste('</br> X is ', x,
'</br> Y is ', y,
'</br> Cat is ', cat
)
)我如何将这两种想法结合起来,这样我就有了一个位置躲避的情节,并且还可以手动设置悬停文本?
发布于 2021-01-07 23:49:11
您可以通过text“美学”传递自定义悬停文本,并将参数tooltip="text"添加到ggplotly调用中。
library(tidyverse)
library(plotly)
df <- data.frame(
x = c(1, 2, 3, 4),
y = runif(8, 5, 10),
cat = c("a", "a", "a", "a", "b", "b", "b", "b")
)
p <- ggplot(df, groups = cat) +
geom_point(aes(x = x, y = y, color = cat,
text = paste('</br> X is ', x, '</br> Y is ', y, '</br> Cat is ', cat)),
position = position_dodge(width = 0.3))
ggplotly(p, tooltip = "text")https://stackoverflow.com/questions/65620848
复制相似问题