Hi Alexandre,
You need to specify the order of the levels of Sex (be default it is lexicographic so Female is first). So replace what you have with:
Sex = factor(c("Male", "Female", "Male", "Female", "Male", "Female", "Male", "Female"), levels = c("Male", "Female"))
For the base boxplot, you need something like:
ggplot(frameEcto, aes(x = Sex, y = FPKM, fill = Compartment)) + geom_boxplot()
Best wishes,
Doug
Hi all,
Sorry, I'm a beginner with ggplot2 and my question is probably stupid...
In my barplot, I would like this order : male and female for each compartment. I looked in ggplot2 documentation to try to do this but without success :S
My code looks like that :
frameEcto=data.frame(Compartment = factor(c("Autosomes", "Autosomes", "PAR", "PAR", "SDR_M", "SDR_M", "SDR_F", "SDR_F")),
FPKM = c(33.43, 34.77, 11.09, 12.57, 16.13, 0.00, 0.00, 18.34),
Sex = factor(c("Male", "Female", "Male", "Female", "Male", "Female", "Male", "Female"))
)
limits <- aes(ymax = FPKM + (5*FPKM/100), ymin=FPKM - (5*FPKM/100))
And for the graphical part :
dodge <- position_dodge(width=0.9)
barplots <- ggplot(frameEcto, aes(fill=Sex, y=FPKM, x=Compartment)) +
geom_bar(position="dodge", stat="identity") +
scale_fill_manual(limits=c("Male","Female"), values = c("cornflowerblue", "hotpink1")) +
scale_x_discrete(limits=c("Autosomes","PAR","SDR_M","SDR_F"), labels = c("Autosomes" = "Autosomes","PAR" = "PAR", "SDR_M" = "Male SDR","SDR_F" = "Female SDR")) +
#labs(title = "Average genes expression level in autosomes, PAR and SDR for each sex") +
ylim(0,40)
barplots + geom_bar(position=dodge) + geom_errorbar(limits, position=dodge, width=0.25)
If I well understood, the "aes(fill=)" works by returning the sex vector values by alphabetical order and is a problem for me. I tried to use the "scale_fill_manual" function but I'm not sur that is the good way to use that (apparently not, there is not effect on the barplot result...).
If someone has a solution, let me know!
Best
Alexandre
--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2
---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
<barplot.png>