Sunday, April 23, 2017

ggtree function in R

As a student in the Organismic and Evolutionary Biology program, I finally have the occasion to compare trait data with phylogenetic data. Over the past couple of weeks, I have been searching for a way to put these things together graphically.

To make the tree of plant species, I have used the "phylomatic" function in R package "brranching" by Scott Chamberlain.

To associate data with the tree, I used Guangchuang Yu's ggtree package. This makes faceted plots where one facet is the tree and another facet (or more) show the data.

First I will offer my thanks to these gurus who make things possible for us R mortals.

Here was the script I came up with:

library(ggplot2)
library(brranching)

#Make the tree:
taxa.plus<- c("Aesculus carnea", "Antirrhinum majus",
              "Brassica napus", "Catalpa speciosa", "Citrus sinensis",
              "Cucurbita pepo", "Dicentra eximia", "Digitalis purpurea",
              "Echium vulgare","Eupatorium perfoliatum", "Fragaria ananassa",
              "Geranium maculatum", "Helianthus annuus",
              "Impatiens capensis", "Kalmia latifolia",
              "Linaria vulgaris", "Lobelia siphilitica",
              "Lythrum salicaria", "Malus domestica",
              "Monarda_didyma",
              "Penstemon digitalis", "Persea americana",
              "Prunus dulcis", "Rhododendron_prinophyllum",
              "Silene vulgaris",
              "Solanum carolinense", "Solidago canadensis",
              "Tilia_cordata", "Thymus vulgaris",
              "Trifolium pratense", "Vaccinium corymbosum",
              "Verbascum thapsis")
treeget<-phylomatic(taxa = taxa.plus, get="GET")
class(treeget)<-"phylo"
plot(treeget)



#Generate data for the graph:
library(plyr)
library(dplyr)
df1<-data_frame(Species=treeget$tip.label,
                Height=runif(n=length(treeget$tip.label), min=10, max=100),
                Chem=rnorm(n=length(treeget$tip.label), mean=5, sd=3))


#Plot in ggtree
library(ggtree)
Tree<-ggtree(as.phylo(treeget)) + geom_tiplab()
#change axis limits to view tip labels
ggtree(as.phylo(treeget)) + geom_tiplab() +
  xlim_tree(30)

#Adjust limits on tree
Tree.l<-Tree + geom_tiplab() + xlim(0,22)

#Creat facet plot:
fp<-facet_plot(Tree, panel = "Chem", data = df1,
           geom = geom_point, aes(x=Chem),
           stat= 'identity') + ggtree::xlim_expand(xlim=c(-2,2), panel="Chem")
fp



#adjust axis limits:
fp.limited<-fp + xlim_tree(40) + xlim_expand(xlim=c(-5, 25), panel = "Chem") +
  theme_tree2()
fp.limited




#Add geom_pointrange:
df1$error<-rnorm(n=length(treeget$tip.label), mean=2, sd=0.4)
fp.error<-facet_plot (fp.limited, geom=geom_pointrangeh, data=df1,
                      aes(x=Chem, xmax = Chem + error, xmin = Chem - error),
                      panel = "Chem")
fp.error





#Try with geom_errobar instead
fp.error.bar<-facet_plot (fp.limited, geom=geom_errorbarh, data=df1,
                      aes(x=Chem, xmax = Chem + error, xmin = Chem - error),
                      panel = "Chem")
fp.error.bar
#Warning: Ignoring unknown aesthetics: x


#However, you get error without specification of "x"
fp.error.bar2<-facet_plot (fp.limited, geom=geom_errorbarh, data=df1,
                          aes(#x=Chem,
                              xmax = Chem + error, xmin = Chem - error),
                          panel = "Chem")
fp.error.bar2
#Error in FUN(X[[i]], ...) : object 'x' not found





Of course I haven't used any real data, but you could!
Good luck plotting!
Evan

Thursday, December 1, 2016

UMass Amherst Life Science Graduate Research Conference

Tomorrow (Friday 2 December) is the UMass Amherst Graduate Research Conference. Stop by the Life Science Laboratory building, Room S330, to hear the latest findings of UMass's graduate students. Or listen on the web live.
EVENT FLYER
Thanks to the LSGRC for organizing this event!

Monday, November 14, 2016

Bumble bee disease on the radio

Fernald Club Blog-founder Evan Palmer-Young was interviewed by a local radio host, Chris Fournier, for a program called Unscripted, which will be played Monday at 8pm on WXOJ-LP 103.3 FM NORTHAMPTON, MA. Topics include the difference between bumble bees and honey bees, Evan's journeys in science, and current and future research themes.

If you want to listen via the live web stream, or your phone -- go Here. Thanks to Chris for doing the interview during daylight hours, and to UMass Journalism Professor Nicholas McBride for facilitating. 

edit: Link to recording is here

Friday, June 24, 2016

Evolution 2016 Austin TX

A big week for the Fernald Club graduate students at the Evolution Conference in Austin TX. Daniel Peterson, Laura Doubleday, and blogger Evan Palmer-Young presented pieces of their dissertation research to an international audience.

Get all the latest entomology talks on the Youtube channel:
https://www.youtube.com/channel/UCLbk92wFKK32tphMS0saI7Q/videos

Here are the highlights from my talk:

https://www.youtube.com/watch?v=OKJ3Efd8LIc
HERE

Relive the glory and follow your colleague through a journey punctuated by
1) Discovering the clicker does not work (0:00)
2) Discovering that there is a microphone, that does work, and makes one's voice audible (1:20)
3) Discovering that the audio system in the conference room is sufficient to alert the bomb squad (4:48)
4) Defining "juggernaut" (12:40)

Thanks to my colleagues for their help getting the talk into shape! Sorry for the choppy delivery. I recorded three talks myself directly before, and missed my zen visualization and warm-up, as well as familiarization with the key A/V equipment.

Wednesday, May 11, 2016

Scientists in the Classroom: Photos

Thanks to Alessandra D'Angelo for hosting me (Evan) in her class, Katie DeMars for signing up for the program, and the Scientists in the Classroom program for inspiring this visit.
Here are some photos:
 Trying out a new phenotype...

Scramble competition!
 Are slides worth beans?
 Competition for resources!
 Maximizing fitness...

Wednesday, May 4, 2016

Scientists in the Classroom, Part II

Last week, Outreach returned to the Morgan Elementary School in Holyoke, MA. This time, I (blog-author Evan Palmer-Young) got to teach a lesson to 4 classes of 6th and 8th graders. The theme of the lecture was, "Evolution by natural selection". I used an activity where students initially varied in phenotypes (cutlery utensils), and had differential reproductive success based on their ability to gather the available food source (beans).

Here are the slides.

Which phenotype do you think was most fit?















Sunday, March 27, 2016

That's good medicine!

On Monday 28 March, Fernald Club's own Scott Schneider defends a thesis on meat-framing ants! (scott's dept page)
Get all the details by going to the defense!

Monday 3/28
 9:30 am
French Hall 209 

Congrats Dr. Scott! Stop by with your stethoscope to give the Fernald Club a periodic checkup!