I have a dataframe which is really two separate results merged into one, each gene has two control sample (FRC190 and FRC193) and 3 unknowns. I would like to plot this in the order you read it, with color grouping for each gene.
SampleID RelativeCopy Loci
1 FRC190 2.040265 ABR
2 FRC193 1.961293 ABR
3 FC124 1.828341 ABR
4 FCP920 2.016274 ABR
5 E-NH021 1.919309 ABR
6 FRC190 1.973149 APRT
7 FRC193 2.027592 APRT
8 FCP604 2.086984 APRT
9 FCP686 2.027592 APRT
10 FCP1130 1.936854 APRT
What I can do is almost that, firstly if I use this code I get the data in the order except the two controls a plotted together.
df <- within(df, SampleID <- factor(
df$SampleID, levels = c('FRC190', 'FRC193', 'FCP920', 'E-NH021',
'FC124', 'FCP1130', 'FCP604', 'FCP686' )))
ggplot(data = df, aes(x=SampleID,y=RelativeCopy, fill = Loci))+scale_fill_grey() +
geom_bar(stat="identity", position=position_dodge())+ theme_classic()
The other option I tried was renaming the controls to different names (i.e. FRC190-1 and FRC190-2) then overwriting the names on the axis. The code used for that is
df <- within(df, SampleID <- factor(
df$SampleID, levels = c('FRC190', 'FRC193', 'FCP920', 'E-NH021', 'FC124',"FRC190-2",
"FRC193-2",'FCP1130', 'FCP604', 'FCP686' )))
ggplot(data = df, aes(x=SampleID,y=RelativeCopy, fill = Loci))+scale_fill_grey()+
geom_bar(stat="identity", position=position_dodge()) + theme_classic() +
scale_x_discrete(breaks=c('FRC190', 'FRC193', 'FCP920', 'E-NH021', 'FC124',"FRC190","FRC193", 'FCP1130', 'FCP604', 'FCP686' ))
This solves the first problem of the grouping of the controls and allows the correct order, but it doesn't allow the use of the same names.