Question: Use facet_plot to display a dot plot of dates (x) vs phylogenetic tree order (y) in R
gravatar for shelley.w.peterson
8 months ago by
shelley.w.peterson10 wrote:

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",
             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.$value) = TRUE

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


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

Please help! TIA

ggplot2 R phylogeny • 278 views
ADD COMMENTlink modified 8 months ago by _r_am32k • written 8 months ago by shelley.w.peterson10

Can you show us the output to:

ADD REPLYlink written 8 months ago by _r_am32k

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 REPLYlink modified 8 months ago • written 8 months ago by shelley.w.peterson10

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

ADD REPLYlink written 8 months ago by _r_am32k

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 REPLYlink modified 8 months ago • written 8 months ago by shelley.w.peterson10

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 REPLYlink written 8 months ago by _r_am32k
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1572 users visited in the last hour