A repository of programs, scripts, and tips essential to
genetic epidemiology, statistical genetics, and bioinformatics
Welcome to the Genome Toolbox! I am glad you navigated to the blog and hope you find the contents useful and insightful for your genomic needs. If you find any of the entries particularly helpful, be sure to click the +1 button on the bottom of the post and share with your colleagues. Your input is encouraged, so if you have comments or are aware of more efficient tools not included in a post, I would love to hear from you. Enjoy your time browsing through the Toolbox.
Showing posts with label scale. Show all posts
Showing posts with label scale. Show all posts
Friday, August 22, 2014
Create Multiple Y Axes for an R Plot
R base graphics is a powerful tool for plotting data. Sometimes it is convenient to visualize combinations of variables on the same plot. Often different variables require different scales. This can be facilitated by using different Y axes, such as a plot with a Y 2 axis on the right hand side. In R adding a Y axis is very easy to do. Here are two simple example scripts you can use to build off of. The first two examples are two different ways of showing different scales for the same variable (i.e. temperature in Farenheit and Celsus). The third example is two different variables overlaid on the same R plot with two Y axes used to show the scales of each variable.
Monday, June 2, 2014
Make Venn Diagram in R with Correctly Weighted Areas
Venn diagrams are incredibly intuitive plots that visually display the overlap between groups. There are a host of programs out there that make Venn diagrams, but very few actually weight the areas correctly to scale. In my opinion, this is unacceptable in the 21st century. I did stumble across one useful R package that calculates the appropriate area for intersections. It is the Vennerable package. While documentation and options are rather light for this package, it does what it needs to do: correctly size overlapping regions.
Its a little tricky to install this Venn diagram package. To do so, follow the below steps:
(1) Type setRepositories() in the R command console.
(2) Select R-forge, rforge.net, CRAN extras, BioC software, and BioC extras in the pop-up window and then press OK. I just have all of them selected.
(3) Install Vennerable package by typing install.packages("Vennerable", repos="http://R-Forge.R-project.org")
(4) Install the dependencies by typing install.packages(c("graph", "RBGL"), dependencies=TRUE).
This should have you up and running. The R Venerable help page can be accessed here, but its really not that useful. Below are some examples you can run as a bit of a primer. The trickiest thing to learn is how the weights are assigned in the Venn plot. As a general rule of thumb, if SetNames=c("A","B","C"), then Weight=c(notABC, A, B, AB, C, AC, BC, ABC). Its a bit frustrating to have no control over general plotting details such as color, label location, and rotation, but I guess I can live with these things for now. Also of note, the plotting algorithm tries its best to converge at a Venn diagram that fits circle areas to your data, but if for some reason it can't there is no guarantee the plot will match your data, so double check things thoroughly! Here are some examples below. If you know of some new or better options out there, please let me know in the comments section. Enjoy.
The output looks like this:
Its a little tricky to install this Venn diagram package. To do so, follow the below steps:
(1) Type setRepositories() in the R command console.
(2) Select R-forge, rforge.net, CRAN extras, BioC software, and BioC extras in the pop-up window and then press OK. I just have all of them selected.
(3) Install Vennerable package by typing install.packages("Vennerable", repos="http://R-Forge.R-project.org")
(4) Install the dependencies by typing install.packages(c("graph", "RBGL"), dependencies=TRUE).
This should have you up and running. The R Venerable help page can be accessed here, but its really not that useful. Below are some examples you can run as a bit of a primer. The trickiest thing to learn is how the weights are assigned in the Venn plot. As a general rule of thumb, if SetNames=c("A","B","C"), then Weight=c(notABC, A, B, AB, C, AC, BC, ABC). Its a bit frustrating to have no control over general plotting details such as color, label location, and rotation, but I guess I can live with these things for now. Also of note, the plotting algorithm tries its best to converge at a Venn diagram that fits circle areas to your data, but if for some reason it can't there is no guarantee the plot will match your data, so double check things thoroughly! Here are some examples below. If you know of some new or better options out there, please let me know in the comments section. Enjoy.
The output looks like this:
Subscribe to:
Posts (Atom)






