Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用R将悬停文本添加到plolty中的方框图中_R_Ggplot2_Plotly_Ggplotly - Fatal编程技术网

使用R将悬停文本添加到plolty中的方框图中

使用R将悬停文本添加到plolty中的方框图中,r,ggplot2,plotly,ggplotly,R,Ggplot2,Plotly,Ggplotly,我已经尝试了一些示例,但无法修复悬停文本 下面是一个简单的例子: library(ggplot2) library(plotly) newhovertext=paste0(iris$Species,"<br>",iris$Sepal.Width) g <- ggplot(iris,aes(x=Species,y=Sepal.Width,label=newhovertext)) + geom_boxplot(alpha=0.5) plotly::ggplotly(g,

我已经尝试了一些示例,但无法修复悬停文本

下面是一个简单的例子:

library(ggplot2)
library(plotly)

newhovertext=paste0(iris$Species,"<br>",iris$Sepal.Width)
g <- ggplot(iris,aes(x=Species,y=Sepal.Width,label=newhovertext)) + 
  geom_boxplot(alpha=0.5) 
 plotly::ggplotly(g,tooltip=label)
库(ggplot2)
图书馆(绘本)
newhovertext=paste0(鸢尾$Species,“
”,鸢尾$Sepal.Width)
g您可以执行以下操作:

library(ggplot2)
library(plotly)
library(datasets)
data(iris)

newhovertext=paste0(iris$Species,"<br>",iris$Sepal.Width)
g<-ggplot(iris,aes(x=Species,y=Sepal.Width, label=newhovertext))+
  geom_boxplot(alpha=0.5)
g %>% ggplotly()

您可以在中看到结果绘图:

不适用于plotly 4.9.1。这是一个我正在运行的简单报告,不需要闪亮。一个你上传的图像截图@大卫,请看另一个链接
gg_box <- iris %>%
  ggplot(aes(x=Species, y=Sepal.Width, text=paste("Species:",Species, "\n",
                                             "Width:", Sepal.Width))) +
  geom_boxplot()+

  #invisible layer of points
  geom_point(alpha = 0)

gg_box %>%
  ggplotly()