This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Need help plotting D statistics

I am trying to generate a figure that looks like the third/bottom portion of this figure (where there are French/Sardinian as Y and others as X) http://www.nature.com/nature/journal/v514/n7523/fig_tab/nature13810_F3.html

I know I need to use ggplot2 to generate these but I don't have an idea how. I was wondering if someone could help

This is my rudimentary code

tbl$RegionX2 <- factor(tbl$RegionX, as.character(tbl$RegionX))
plot <- ggplot(tbl, aes(y = RegionX2, 
            x = D, xmin = D - 2*SE, xmax = D + 2*SE, label = RegionX2, colour = RegionY)) + 
    geom_point(colour = "black") + 
  geom_text(hjust = 1.2) + 
  theme_classic() + 
  theme(axis.title = element_blank(),
        axis.ticks = element_blank(), 
        axis.text.y = element_blank(), 
        legend.position = "none") + 
  geom_errorbarh(height = 0)
ggsave(plot=plot,height=7,width=7, filename="D.pdf", useDingbats=FALSE)

It plots like this http://imgur.com/a/qmCeg

But I don't know how to keep Region A and B from stacking on top of eachother, to get the x=0 line, or to get the X and Y labels as they are in that figure. Can anyone help?

Also, my data is formatted as such:

RegionX RegionY D   SE
WestAfrica  A   -0.027  3.14E-03
EastAfrica  A   -0.0234 2.82E-03
SouthAsia   A   0.0048  1.68E-03
Caucasus    A   0.0052  1.17E-03
EastAsia    A   0.0067  3.58E-03
WestAfrica  B   -0.028  3.14E-03
EastAfrica  B   -0.0244 2.82E-03
SouthAsia   B   0.0038  1.68E-03
Caucasus    B   0.0042  1.17E-03
EastAsia    B   0.0057  3.58E-03
r

For the points you can use geom_jitter() instead of geom_point() to add a small offset and avoid overlapping.

And for the text: geom_text(position=position_jitter())

Also consider using geom_text_repel() in the ggrepel package. See for example the vignette here.

0 answers

No answers yet.

Log in to answer this question.