R 如何在ggplotly中自定义工具提示?
我想对ggplotly的工具提示中的值进行四舍五入 我有代码,当你把鼠标悬停在一列上时,它会显示完整的值 我检查了文件,但很难找到说明 这是我的密码R 如何在ggplotly中自定义工具提示?,r,ggplot2,ggplotly,R,Ggplot2,Ggplotly,我想对ggplotly的工具提示中的值进行四舍五入 我有代码,当你把鼠标悬停在一列上时,它会显示完整的值 我检查了文件,但很难找到说明 这是我的密码 library(fpp) library(plotly) library(tidyverse) gg <- credit %>% ggplot(aes(score)) + geom_histogram(fill = "lightblue") + theme_
library(fpp)
library(plotly)
library(tidyverse)
gg <-
credit %>%
ggplot(aes(score)) +
geom_histogram(fill = "lightblue") +
theme_ipsum_rc(grid = "XY") +
labs(title = paste0("Histogram: "),
x = "")
ggplotly(gg)
库(fpp)
图书馆(绘本)
图书馆(tidyverse)
gg%
ggplot(aes(分数))+
几何图形直方图(fill=“浅蓝色”)+
theme_ipsum_rc(grid=“XY”)+
实验室(标题=0(“直方图:”),
x=“”)
ggplotly(gg)
当我将鼠标悬停在其中一列上时,它将值显示为完整的数字(60.2312)
我想展示它的四舍五入版本,因此它显示的是60,而不是这可以通过在
文本上映射一个格式化字符串来实现,例如,要显示分数,您可以使用粘贴(“分数:,刻度::数字(分数,精度=1))
。这会在工具提示中添加另一个条目,您必须添加选项tooltip=list(“text”,“count”)
,以防止得分的默认条目:
library(fpp)
library(plotly)
gg <-
credit %>%
ggplot(aes(score)) +
geom_histogram(aes(text = paste("score:", scales::number(score, accuracy = 1))), fill = "lightblue") +
labs(title = paste0("Histogram: "),
x = "")
ggplotly(gg, tooltip = list("text", "count"))
库(fpp)
图书馆(绘本)
gg%
ggplot(aes(分数))+
geom_直方图(aes(文本=粘贴(“分数:”,刻度::数字(分数,精度=1))),fill=“浅蓝色”)+
实验室(标题=0(“直方图:”),
x=“”)
ggplotly(gg,工具提示=列表(“文本”、“计数”))