2

I am trying to create a graph showing the number of citations that papers from a department have received. I want it to be an interactive plot so more information is displayed when hovering a particular entry.

The papers with few citations are suppressed in the ggplotly version, but I would like them so still be shown as in the ggplot.

This is the code I am using:

library(tidyverse)
library(plotly)

download.file("https://raw.githubusercontent.com/luizaandrade/dec-bibliometrics-dashboard/main/citations.rds",
              "data.rds", 
              method = "curl")

data <- readRDS("data.rds")

graph <-
  data %>%
    ggplot() +
    geom_segment(
      aes(x = year_scholar,
          xend = year_scholar,
          y = start,
          yend = end,
          color = year_id,
          text = paste0(title, "<br>",
                        all_authors, "<br>",
                        journal, "<br>",
                        "Citations: ", cites)),
      size = 10, 
      lineend = "butt")

ggplotly(graph,
         tooltip = "text")

The ggplot looks like this:

enter image description here

And the plotly version looks like this:

enter image description here

Any suggestions?

1 Answers1

0

Why not with geom_col?

graph <- ggplot(data) +
    geom_col(
        aes(x = year_scholar,
            y = cites,
            fill = year_id,
            text = paste0(title, "<br>",
                          all_authors, "<br>",
                          journal, "<br>",
                          "Citations: ", cites)),
        size = 10)

pl_graph <- ggplotly(graph,
                     tooltip = "text")
pl_graph

enter image description here

Roman
  • 4,744
  • 2
  • 16
  • 58
  • Because I wanted to use different colors to highlight the papers with the highest number of citations. I'd like it to look like [this](https://github.com/worldbank/dec-bibliometrics-dashboard/issues/3) in the end. If I use `geom_col`, all the red marks are shown in the bottom of them column. – Luíza Andrade Nov 15 '21 at 22:12