如何自定义 ggplotly 对象中的悬停信息? [英] How to customize hover information in ggplotly object?

查看:73
本文介绍了如何自定义 ggplotly 对象中的悬停信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在 ggplotly 对象中自定义 hoverinfo?

Is there a way to customize hoverinfo in a ggplotly object?

例如

p <- ggplot(mtcars, aes(x = disp, y= am, color = as.factor(cyl)))+geom_point()

ggplotly(p)

这里的悬停信息框包含三个变量:disp、am和factor(cyl).如何在悬停信息框中包含更多变量或排除现有变量?

The hover information box here contains three variables:disp,am and factor(cyl). How to include more variables or exclude existing variables in the hover information box?

谢谢!

推荐答案

您可以在 aes() 中包含所需的变量,然后使用 tooltip 指定应该显示的变量:

You can include required variables in aes() then use tooltip to specify which should be displayed:

p <- ggplot(mtcars, aes(x = disp, y= am, color = as.factor(cyl), 
                        gear=gear, hp=hp))+geom_point()
ggplotly(p,tooltip = c("x", "gear", "hp"))

这篇关于如何自定义 ggplotly 对象中的悬停信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆