Skip to content
Snippets Groups Projects
plots.R 1.28 KiB
Newer Older
library(ggplot2)

# This assumes that the master script ran through and the result data frame is available

feature_count <- sapply(results, function(col) sum(length(which(!is.na(col)))))
feature_count <- data.frame(Count <- feature_count,
                            Feature <- colnames(results),
                            stringsAsFactors = FALSE)
feature_count <- feature_count[feature_count$Count > 0 & feature_count$Feature != "name",]
colnames(feature_count) <- c("Count", "Feature")

# Flipped coord barplot
p <- ggplot(feature_count, aes(x = reorder(Feature, Count), y = Count, fill = Feature))
p <- p + geom_bar(stat = "identity", width = 0.5)
p <- p + geom_hline(aes(yintercept = 983), colour = "red")
p <- p + coord_flip()
p <- p + guides(fill = FALSE)
p <- p + theme_minimal()
p <- p + labs(x = "Feature")
p
ggsave("feature_count_flip.png", path = "plots", width = 4, height = 4, units = "in")

# Normal barplot
p <- ggplot(feature_count, aes(x = reorder(Feature, -Count), y = Count, fill = Feature))
p <- p + geom_bar(stat = "identity", width = 0.5)
p <- p + geom_hline(aes(yintercept = 983), colour = "red")
p <- p + theme_minimal()
p <- p + theme(axis.text.x=element_blank())
p <- p + labs(x = "Feature")
p
ggsave("feature_count_normal.png", path = "plots", width = 4, height = 4, units = "in")