I would like to create a cloud which shows information about the point using tooltip in ggiraph packages. I can create a cloud with only one information (from one column), but I would like to add information from three columns. Below I added a picture what I want to achieve and code. The code is correct but on the plot is information from only one column.
Picture shows what I want to achieve
#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)
You can use paste0
to get the tooltip with all the values as follows:
df$tooltip <- c(paste0("Name = ", df$col_C, "\n Column A = ", df$col_A, "\n Column B = ", df$col_B))
Then instead of geom_point_interactive(tooltip=df$col_C)
you can use geom_point_interactive(tooltip=df$tooltip)
Hope it helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With