Skip to content

Instantly share code, notes, and snippets.

@davetang
Created June 16, 2017 08:57
Show Gist options
  • Save davetang/f1fecbe8c3e683993b0c5cb3f13b4c97 to your computer and use it in GitHub Desktop.
Save davetang/f1fecbe8c3e683993b0c5cb3f13b4c97 to your computer and use it in GitHub Desktop.
#!/usr/bin/env Rscript
#
# Usage: plot_gemini.R <file.tsv>
#
my_required <- c('ggplot2', 'reshape2', 'ggthemes')
for (my_package in my_required){
if(my_package %in% rownames(installed.packages()) == FALSE){
stop(paste("Please install", my_package, "first"))
}
}
library(ggplot2)
library(reshape2)
library(ggthemes)
args <- commandArgs(TRUE)
if (length(args) != 1){
stop('Please provide input file')
}
my_file <- args[1]
my_pdf <- gsub(pattern = 'tsv', replacement = 'pdf', x = my_file)
df <- read.table(my_file, header = TRUE, stringsAsFactors = FALSE)
names(df) <- c('foobar', 'Count')
df$foobar <- factor(df$foobar, levels = df$foobar)
df_melt <- melt(df)
my_plot <- ggplot(df_melt, aes(x = foobar, y = value, fill = foobar, label = value)) +
geom_bar(stat = "identity") +
theme(axis.title.x = element_blank(),
axis.text.x = element_blank(),
axis.ticks.x = element_blank(),
legend.title = element_blank()) +
labs(y = 'Count', x = element_blank()) +
theme_hc() +
geom_text()
ggsave(filename = my_pdf, plot = my_plot, dpi = 150, width = 30, height = 20, units = 'cm')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment