0

I have data that looks like:

    sp sample_name  homo_anc     het homo_dev Heterozygozity
1   BF      RSFV1M 835314771 1857148  2106125      0.2212792
2   BF      RSFV1N 832516832 3049895  1576519      0.3643218
3   BF      RSFV1O 834367309 2651230  1762650      0.3160813
4   BF      RSFV1P 828847720 2902735  1604046      0.3483194
5   BF      RSFV1Q 835338722 2261941  1948946      0.2694231

...

21 WBM      RSFV1I 833924008 3378924  2285658      0.4024499
22 WBM      RSFV1J 833263882 3324019  2333676      0.3962252
23 WBM      RSFV1L 828667189 3354676  2266616      0.4021003

and am trying to plot as a geom_dotplot using:

p <- ggplot(het, aes(x=sp, y=Heterozygozity, fill=sp, colour=sp))+
     geom_dotplot(binaxis = "y", binwidth = 0.002, stackdir = "center", dotsize=7, binpositions="bygroup") +

  # Custom the theme:
  theme_bw() +
  theme( 
    legend.position="none",
    panel.border = element_blank(),
    panel.grid.major.x = element_blank(),
    panel.grid.minor.x = element_blank(),
    axis.title.x=element_blank(),
    axis.ticks.x=element_blank()
  )

but there's too much space between the two categories BF and WBM plus I need the order the show up in the x axis to be the same as in the data. I tried to add coord_fixed(ratio = 3) but it just smashes the plot on the horizontal, and I tried to fix the order by doing aes(x=sort(sp)... but It only reorder the labels without moving the data points.

  • 1
    Could you make your problem reproducible by sharing a sample of your data so others can help (please do not use `str()`, `head()` or screenshot)? You can use the [`reprex`](https://reprex.tidyverse.org/articles/articles/magic-reprex.html) and [`datapasta`](https://cran.r-project.org/web/packages/datapasta/vignettes/how-to-datapasta.html) packages to assist you with that. See also [Help me Help you](https://speakerdeck.com/jennybc/reprex-help-me-help-you?slide=5) & [How to make a great R reproducible example?](https://stackoverflow.com/q/5963269) – Tung Oct 29 '18 at 04:53
  • Your data doesn't have the columns in `reorder(State, Crude.Rate)`. – Rui Barradas Oct 29 '18 at 05:02
  • 1) You cannot have `x = something` twice in the same function call. 2) Two themes gives an `Error: Cannot add ggproto objects together. Did you forget to add this object to a ggplot object?` – Rui Barradas Oct 29 '18 at 05:11
  • That was an error. Now the code is the way I run. Thanks – Madza Farias-Virgens Oct 29 '18 at 20:34

0 Answers0