sa-lee / starmie

starmie: plotting and inference for population structure models :star2:
Other
12 stars 6 forks source link

Generate barplot #3

Closed gtonkinhill closed 8 years ago

gtonkinhill commented 8 years ago

Take the output of the load admixture and load structure function and generate a stacked barplot split by K.

Input: The output of load structure or load admixture

Output: A ggplot2 object

gtonkinhill commented 8 years ago

Some example code

gg <- ggplot(QData.df, aes(x=SampleID, y=value, fill=factor(Cluster)))
gg <- gg + facet_grid( K ~ FamilyID, scales = "free_x", space = "free_x")
gg <- gg + geom_bar(stat = "identity", width=1, binwidth=0)
gg <- gg + scale_fill_manual(values = cols[1:length(unique(QData.df$Cluster))])
gg <- gg + scale_y_continuous(expand=c(0,0), breaks=c(0.25,0.75))
gg <- gg + xlab("Sample ID") + ylab("Proportion of cluster")
gg <- gg + theme_bw()
gg <- gg + theme(panel.grid=element_blank()
                 , panel.border=element_blank()
                 , panel.grid.minor=element_blank()
                 , panel.grid.major=element_blank()
                 , axis.text.x=element_blank()
                 , axis.ticks.x=element_blank()
                 , strip.text.x = element_text(size = 8, angle = 90)
                 , legend.position="none")
gg
sa-lee commented 8 years ago

Apparently this is how you make ggplot work with S3 objects - use fortify + autoplot http://stackoverflow.com/questions/7098830/bad-idea-ggplotting-an-s3-class-object http://docs.ggplot2.org/0.9.3.1/autoplot.html