代码之家  ›  专栏  ›  技术社区  ›  user3224522

根据X递增值排列Y轴标签

r
  •  0
  • user3224522  · 技术社区  · 4 年前

    我有这样的数据

    z <- structure(list(Description = c("Neurotransmitter receptors and postsynaptic signal transmission", 
    "Muscle contraction", "Class A/1 (Rhodopsin-like receptors)", 
    "Signaling by Rho GTPases", "Metabolism of carbohydrates", "Extracellular matrix organization", 
    "Transmission across Chemical Synapses", "G alpha (i) signalling events", 
    "GPCR ligand binding", "Neuronal System"), p.adjust = c(0.563732077253957, 
    0.563732077253957, 0.774251160588198, 0.797669099976286, 0.655931854998983, 
    0.655931854998983, 0.563732077253957, 0.774251160588198, 0.774251160588198, 
    0.655931854998983), Count = c(9L, 9L, 9L, 9L, 10L, 10L, 11L, 
    11L, 12L, 13L)), row.names = c("R-HSA-112314", "R-HSA-397014", 
    "R-HSA-373076", "R-HSA-194315", "R-HSA-71387", "R-HSA-1474244", 
    "R-HSA-112315", "R-HSA-418594", "R-HSA-500792", "R-HSA-112316"
    ), class = "data.frame")
    

    我想根据x轴的值绘制y轴的标签,从最小的到最大的。现在它按字母顺序绘制我。怎么做?

    ggplot(z, aes(Count, Description, size=Count, color=p.adjust))+
      geom_point()
    

    像这样的人

    enter image description here

    0 回复  |  直到 4 年前
        1
  •  1
  •   Peter    4 年前

    具有 forcats::fct_reorder(Description, Count) 可以更改y值的顺序。

    library(ggplot2)
    library(forcats)
    
    ggplot(z, aes(Count, fct_reorder(Description, Count), size=Count, color=p.adjust))+
      geom_point()
    

    于2022-02-01年由 reprex package (v2.0.1)