How to choose variable to display in tooltip when using ggplotly?

前端 未结 4 1226
[愿得一人]
[愿得一人] 2020-11-28 22:01

I have a simple data frame:

seq <- 1:10
name <- c(paste0(\"company\",1:10))
value <- c(250,125,50,40,40,30,20,20,10,10)
d <- data.frame(seq,name,         


        
4条回答
  •  独厮守ぢ
    2020-11-28 22:40

    Building on @UweBlock's answer, you can also create dummy aesthetics in order to display multiple labels in tooltips. I can't find where this is documented, but discovered it emperically. The dummy variables show up in the order you specify them, but priority is given to the default variables (e.g. x and y). To get around this, you can specify those variables in a separate aesthetic, as shown below:

    library(plotly)
    p = ggplot(iris, aes(label=Species, label2=Petal.Length, label3=Petal.Width)) + 
      geom_point(aes(Sepal.Length,Sepal.Width))
    ggplotly(p)
    

提交回复
热议问题