Created
February 11, 2015 16:48
-
-
Save simecek/8a837633d86219ee12fa to your computer and use it in GitHub Desktop.
Interactive scatterplot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example of ggvis scatterplot | |
# on over - display MGI gene symbol | |
# on click - open browser with Ensembl page | |
library(ggvis) | |
# load dataset | |
dataset <- read.csv("http://dl.dropboxusercontent.com/u/232839/DO_liver_variability_sex.csv", as.is=TRUE) | |
head(dataset) | |
# what to do on hover | |
on_hover <- function(x) { | |
if(is.null(x)) return(NULL) | |
mgi_symbol <- dataset$Associated.Gene.Name[x$id] | |
mgi_symbol | |
} | |
# what to do on click | |
on_click <- function(x) { | |
if(is.null(x)) return(NULL) | |
ensid <- dataset$Ensembl.Gene.ID[x$id] | |
ensembl_url <- paste0("http://useast.ensembl.org/Mus_musculus/Gene/Summary?db=core;g=", ensid) | |
browseURL(ensembl_url) | |
NULL | |
} | |
# start ggvis | |
point_size = 100 # if dots are too big/small, adjust this parameter | |
dataset %>% | |
ggvis(~protein.Sex, ~mrna.Sex, key := ~id) %>% | |
layer_points(size := point_size) %>% | |
add_tooltip(on_hover, "hover") %>% | |
add_tooltip(on_click, "click") %>% set_options(width=600, height=600) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi there, thanks for sharing the code to this! I'm getting a
404
error when trying to download the data - is the data available at a different url?