代码之家  ›  专栏  ›  技术社区  ›  J.Con

在ggplot x轴-r上显示所有日期值

  •  1
  • J.Con  · 技术社区  · 7 年前

    在下面的小数据集中,我想在X轴上绘制日期值。我希望对数据框中的所有日期标记。目前,它只标记了3个随机滴答。我可以把这个列改成一个因子,但是日期意味着x轴是根据点之间的时间间隔来划分的。到目前为止,我能找到的唯一答案是每个月都要展示的问题,或者至少是间隔相等的时间间隔。我只想显示数据集中的值。谢谢你

    数据:

    dput(熔化)
    结构(列表(示例=结构(C(16023、16023、16027、16027,
    16031、16031、16035、16035、16038、16038、16044、16044、16023、
    16023、16027、16027、16031、16031、16035、16035、16038、16038、
    1604416044),class=“date”),treatment=结构(c(1l,2l,
    1L、2L、1L、2L、1L、2L、1L、2L、1L、2L、1L、2L、1L、2L、1L、2L、
    1L,2L,1L,2L,1L,2L),.label=c(“T1”,“T5”),class=“factor”),
    变量=结构(C(1L,1L,1L,1L,1L,1L,1L,1L,1L,1L,
    1L、1L、1L、2L、2L、2L、2L、2L、2L、2L、2L、2L、2L、2L、2L、2L
    ),.label=c(“20:5n-3”,“20:4n-6”),class=“factor”),value=c(1.21879849498785,
    1.88548990818282,1.87990774775065,1.25350826053539,3.10352691206175,
    1.18465888918519,3.15176346709818,1.82106970985234,2.73680349074891,
    1.58066166099405,1.43967823968644,1.51515884762159,9.25194151767438,
    9.232798648857,14.0535236345336,9.06572816754405,9.90634511302451,
    10.0962470101343,7.44314990623579,12.7996706096935,5.96573623304832,
    8.070195431115,2.57433899670204,11.4388591839374)),row.names=c(na,
    -24L),class=“data.frame”)。
    < /代码> 
    
    

    代码:

    库(ggplot2)
    
    ggplot(熔化,aes(x=样品,y=值,颜色=变量,组=变量))。+
    面包(治疗)+
    GeoMangPooPoT()+
    GeoMyLink()
    < /代码> 
    
    

    绘图:

    .

    数据:

    dput(melt)
    structure(list(Sample = structure(c(16023, 16023, 16027, 16027, 
    16031, 16031, 16035, 16035, 16038, 16038, 16044, 16044, 16023, 
    16023, 16027, 16027, 16031, 16031, 16035, 16035, 16038, 16038, 
    16044, 16044), class = "Date"), Treatment = structure(c(1L, 2L, 
    1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 
    1L, 2L, 1L, 2L, 1L, 2L), .Label = c("T1", "T5"), class = "factor"), 
        variable = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
        1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L
        ), .Label = c("20:5n-3", "20:4n-6"), class = "factor"), value = c(1.21879849498785, 
        1.88548990818282, 1.87990774775065, 1.25350826053539, 3.10352691206175, 
        1.18465888918519, 3.15176346709818, 1.82106970985234, 2.73680349074891, 
        1.58066166099405, 1.43967823968644, 1.51515884762159, 9.25194151767438, 
        9.23279864348857, 14.0535236345336, 9.06572816754405, 9.90634511302451, 
        10.0962470101343, 7.44314990623579, 12.7996706096935, 5.96573623304832, 
        8.070195431115, 2.57433899670204, 11.4388591839374)), row.names = c(NA, 
    -24L), class = "data.frame")
    

    代码:

    library(ggplot2)
    
    ggplot(melt, aes(x=Sample, y=value, colour=variable, group=variable))+
      facet_wrap(~Treatment)+
      geom_point()+
      geom_line()
    

    情节:

    1 回复  |  直到 7 年前
        1
  •  3
  •   neilfws    7 年前

    您可以提供 melt$sample as the breaks.您可能还需要旋转轴标签以避免重叠。

    ggplot(熔化,aes(x=样品,y=值,colour=变量,group=变量))。+
    面包(治疗)+
    GeoMangPooPoT()+
    GeoMyLink()+
    缩放日期(中断=融化$sample)+
    主题(axis.text.x=element_text(angle=90))
    < /代码> 
    
    

    enter image description here

    推荐文章