# load simulated admixture data
data("xadmixture")
# for data frame with ancestries (K) in fourth to last column,
# without showing bar labels
admix_barplot(xadmixture,
K = 4:ncol(xadmixture),
names = FALSE
)
# grouping data by column "country",
# and sorting each group by ancestry column "K1"
admix_barplot(xadmixture,
K = 4:ncol(xadmixture),
grouping = "country",
sortkey = "K1",
names = FALSE
)
# changing color palette to "turbo" from package 'viridis',
admix_barplot(xadmixture,
K = 4:ncol(xadmixture),
palette = "turbo",
names = FALSE
)
# removing title and changing axis labels text
admix_barplot(xadmixture,
K = 4:ncol(xadmixture),
main = "",
xlab = "Accessions",
ylab = "Ancestry [%]",
names = FALSE
)
# directly output grouped plot with clipping removed from elements
# (useful if there are groups with a low number of observations)
# create a subset of the data
xadmixture_sub <- admix_subset(xadmixture,
anc = c("K3", "K4"),
pct = c(0.3, 0.2))
# generate a grouped & sorted stacked barplot
# setting "noclip" to "TRUE" may require opening a new graphics device
dev.new()
admix_barplot(xadmixture_sub,
K = 4:ncol(xadmixture),
sortkey = "K5",
grouping = "country",
palette = "viridis",
names = FALSE,
noclip = TRUE)
dev.off()
Run the code above in your browser using DataLab