geom_dotplot中的订购类别

时间:2018-10-29 04:42:11

标签: r ggplot2

我的数据如下:

    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

并尝试使用以下图形绘制为geom_dotplot:

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()
  )

但是BF和WBM这两个类别之间的空间太大,而且我需要在x轴上显示的顺序与数据中的顺序相同。我尝试添加coord_fixed(ratio = 3),但它只是捣碎了水平图,我尝试通过执行aes(x=sort(sp)...来固定顺序,但它只对标签重新排序而没有移动数据点。

0 个答案:

没有答案
相关问题