Skip to content

Adding a html link to a bar graph #1109

@anusurendra

Description

@anusurendra

Hi,

I am new to plotly, but found it is a great tool for creating interactive graphs. I created a bar graph using ggplot and would like to make each of the rectangles a clickable link to a website. Is there a easy way to do that. In order to bypass the issue I have placed the link in the tooltip (I have attached the html file I generated test_index.html.zip). However, this is not ideal. Any help would be appreciated.
Below is the code I used:

p1<-ggplot(data=gene.symbol.count.melt.m,aes(label=description,label2=link)) +
      geom_bar(aes(x=symbol, y=symbol_count),stat="identity",fill = "cornflowerblue")  + ylab("Count") + xlab("Gene Symbol") +
      ggtitle(paste("Histogram of Gene Counts for Search \"",dd," ",term,"\"",sep="")) + guides(fill=FALSE) +
      theme(axis.text.x = element_text(angle = 90, hjust = 1),
            panel.grid.major = element_line(colour = "grey80"),
            panel.grid.minor = element_blank(),
            panel.border = element_rect(colour = "black", fill=NA),
            panel.background = element_blank(),plot.title = element_text(hjust = 0.5))
    #print(p1);
    gp<-ggplotly(p1)
    
    gp$x$data[[1]]$text<-c("symbol: <a href='https://bioinfo.nrc.ca/mwfd/search.php?ddID=target&term=dao'>DAO</a>","symbol: <a href='https://bioinfo.nrc.ca/mwfd/search.php?ddID=target&term=Slc22a20'>Slc22a20</a>")
    htmlwidgets::saveWidget(gp, "~/test_index.html")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions