我用ggplotly做了一个条形图。在工具提示中,它始终显示如下文本paste(hp, 'hp') 335 hp
。我需要的就像这样的格式:hp: 335 hp
.我不知道为什么会这样。 有谁知道如何解决这个问题?
library(tidyverse)
library(plotly)
mtcars$cars = row.names(mtcars)
g = mtcars %>%
arrange(desc(hp)) %>%
head(., 10) %>%
ggplot(aes(x= reorder(cars, hp), y=hp,
text=cars, text1 = paste(hp, 'hp') ))+
geom_bar(stat='identity', fill='darkred')+
coord_flip()
ggplotly(g, tooltip = c("text","text1") )
尝试将所有文本放入一行并使用新的换行符n
:
library(tidyverse)
library(plotly)
mtcars$cars = row.names(mtcars)
g = mtcars %>%
arrange(desc(hp)) %>%
head(., 10) %>%
ggplot(aes(x= reorder(cars, hp), y=hp,
text = paste0(cars, "n", "hp: ", hp) ))+
geom_bar(stat='identity', fill='darkred')+
coord_flip()
ggplotly(g, tooltip = c("text","text1") )