我想创建一个云,它使用 ggiraph 包中的工具提示显示有关该点的信息。我可以创建一个只有一个信息(来自一列)的云,但我想添加来自三列的信息。下面我添加了一张我想要实现的图片和代码。代码是正确的,但图中只有一列的信息。
#lib.
library(ggiraph)
library(ggplot2)
library(shiny)
#create data frame
col_A=c(123,523,134,543,154)
col_B=c(100,200,300,400,500)
col_C=as.character(c("food_1", "food_2", "food_3", "food_4", "food_5"))
df=data.frame(col_A, col_B, col_C)
df$col_C <- as.character(df$col_C)
#ui.
ui <- fluidPage(
ggiraph::ggiraphOutput("plot1"))
#server
server <- function(input, output) {
gg <- ggplot(data = df ,aes(x = col_A, y = col_B)) +
geom_point_interactive(tooltip=df$col_C)
# I would like to plot like this: geom_point_interactive(tooltip=c(df$col_A, df$col_B, df$col_C))
# but i causes error: Aesthetics must be either length 1 or the same as the data (5): tooltip
output$plot1 <- renderggiraph({
ggiraph(code= print(gg))})
}
shinyApp(ui = ui, server = server)