热地删除某些部分的悬停文本

mon*_*ica 3 r shiny plotly

plotly悬停文本的默认选项中,我有 3 行文本,我想删除两行并只留下一行显示“计数”+“观察次数”

这条线不做任何事情

mode = 'text', text = ~Count, 
Run Code Online (Sandbox Code Playgroud)

我还有 3 行文字,感谢您的帮助

p1 <- ggplot(cancer0, 
        mode = 'text', text = ~Count, 
        aes(x = cancer10[,1], 
        fill = cancer10[,2])) + geom_bar(position = input$pos) + 
        xlab("Factor") + ylab("Count") + theme_bw()

ggplotly(p1) %>% config(displayModeBar = F)
Run Code Online (Sandbox Code Playgroud)

这是输出的屏幕截图:

截屏

Mar*_*dri 5

这是基于text美学的解决方案:

cancer10 <- read.table(text="
Id Sex Count
A F 0  
A M 5
B F 7
B M 20
C F 17
C M 36
D F 22
D M 80
E F 40
E M 80", header=T)

library(ggplot2)
p1 <- ggplot(cancer10, aes(x = Id, y=Count, fill = Sex, 
        text = paste("Count:", Count))) + 
        geom_bar(stat="identity", position="dodge") + 
        xlab("Factor") + ylab("Count") + theme_bw()

library(plotly)
ggplotly(p1, tooltip="text") %>% config(displayModeBar = F)
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明