Use facet_plot to display a dot plot of dates (x) vs phylogenetic tree order (y) in R
0
0
Entering edit mode
4.0 years ago

I am trying to generate a dot plot alongside my phylogenetic tree, with x axis = date and y axis is sample in the same order as a phylogenetic tree. dd5 is my info table and p2 is my tree.

dd5 <- drop_na(data.frame(id = dd2$Number, value = as.Date(dd2$Date.Collected, "%Y-%m-%d", origin = "2000-01-01"), prov = dd2$Province))
p4 <- facet_plot(p2, "Sample Date",
             data=dd5,
             geom = geom_point,
             mapping = aes(x = value, color = Province)

When I run this code, I get

> Error in as.Date.numeric(value): 'origin' must be supplied.

is.date(dd5$value) = TRUE

and I get the same error whether or not I include as.Date or an origin

Using

mapping = aes(x = as.numeric(as.Date(value)),  color = Province)

gives me the dot plot I want, but I need the x axis to show the actual dates.

If I add scale_x_date, I get the error

> Invalid input: date_trans works with objects of class Date only

despite the fact that is.date=TRUE

Please help! TIA

R phylogeny ggplot2 • 1.3k views
ADD COMMENT
0
Entering edit mode

Can you show us the output to:

head(dd2)
head(dd5)
ADD REPLY
0
Entering edit mode

dd2 is really large, but here's dd5 (the columns match as expected)

         id      value prov
1 ERR1515431 2011-01-01   UK
2 ERR1515463 2011-01-01   UK
3 ERR1515483 2011-01-01   UK
4 ERR1515516 2012-01-01   UK
5 ERR1515525 2012-01-01   UK
6 ERR1515541 2012-01-01   UK

One more thing to add is that one of the rows has NA for date. I still get the same error if I put a dummy date in, so that shouldn't be the problem.

ADD REPLY
0
Entering edit mode

I'm trying to reproduce your problem. What is p2?

ADD REPLY
0
Entering edit mode

It's a phylogenetic tree showing the relatedness between the samples. The order of the samples in the phylogenetic tree is how they should be plotted on the y axis on the dot plot.

p2 <- ggtree(phylo) %<+% dd2 +
  geom_tippoint(shape = 21, aes(fill = Province), size=2.75, color = "black", stroke = .025,  alpha = 1, na.rm = FALSE)+
  scale_fill_manual(values = iColours)+
  theme(legend.position =  "right")+
  geom_treescale(y= -9, fontsize = 3)
ADD REPLY
0
Entering edit mode

Sorry, I'm not familiar with ggtree, and this seems a little too complicated for me to reproduce here. I'd recommend chipping away at it until you get to the root of what is failing.

ADD REPLY

Login before adding your answer.

Traffic: 1517 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6