[ad_1]
Possibly this question has been asked before but I don’t manage to find a solution.
I have a TSV (test.tsv) that looks like this:
TPM variants NOI_ID HLA NAL
324.28 several p1 one 2
169.21 NA p1 two 15
154.78 NA p1 three 0
143.31 NA p1 four 2
468.7 NA p2 five 0
322.76 several p2 six 2
620.98 NA p2 two 0
591.17 NA p2 seven 0
637.74 NA p3 eight 4
519.8 NA p3 nine 10
1439.58 NA p3 ten 23
122.05 NA p4 five 14
149.74 NA p4 eleven 77
213.7 NA p4 twelve 100
162.53 NA p4 one 15
Using this code:
fig13 <- read.table("test.tsv", sep="\t", header=T, check.names=FALSE)
fig13 = fig13[-which(grepl("_w8", fig13$NOI_ID)),]
fig13_melt <- melt(fig13[c("TPM", "NOI_ID", "HLA", "variants")], id=c("NOI_ID", "HLA", "variants"))
hla_barplot = ggplot(fig13_melt, aes(x=1:nrow(fig13_melt), y=value, fill=variants)) +
geom_bar(stat="identity", position="dodge") + ggtitle("HLA status", subtitle = "all samples") + theme_bw() +
theme(axis.title.y=element_blank(), axis.title.x=element_blank(),
plot.title = element_text(face = "bold", size = 15, hjust = 0.5),
plot.subtitle=element_text(size=12, hjust=0.5, face="italic"),
axis.text.y = element_text(size=6),
axis.text.x = element_text(angle = 90, hjust=1, size=6)) +
geom_text(aes(label = round(value,0), vjust = 1, size = 1)) +
scale_x_discrete(labels=fig13_melt$HLA, breaks=1:nrow(fig13_melt), limits=factor(1:nrow(fig13_melt)), name="HLA")
hla_barplot
However when I try to use facet_wrap to split the plot:
hla_barplot + facet_wrap(.~ NOI_ID, nrow = 1)
I get the following:
So, as far as I can see, each subplot has all the x labels of the whole dataset. Is there a way to just plot in the x-axis the labels of each subgroup?
[ad_2]