I have the following data.
pos <- c(1,2,3,4,5,6,1,2,3,4,5,6,1,2,3,4,5,6,1,2,3,4,5,6)
block <- c(1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2)
set <- c(1,1,1,1,1,1,2,2,2,2,2,2,3,3,3,3,3,3,4,4,4,4,4,4)
fsize <- c(4,5,6,1,2,1,2,2,3,4,5,1,7,11,2,1,2,3,5,3,5,6,1,2)
dat <- data.frame(pos,block,set,fsize)
dat <- dat[order(block,set,-fsize),]
dat$pos <- as.factor(dat$pos)
ggplot(dat, aes(x = pos, y = fsize)) + geom_bar(stat="identity") +
facet_wrap(~block+set)
Each position pos
is associated with a size fsize
. There are 6 positions within each block/set. I want to arrange the sizes in decreasing female size.
So for example, the first block/set with rearranged positions would be 3,2,1,5,4,6
and it would be different for the other. However, when I plot it, the x-axis gets automatically reordered to 1-6 even when I factor the pos
column. Any suggestions on how to rectify this?