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

在ggplot x轴-R上显示所有日期值,r,date,ggplot2,R,Date,Ggplot2,在下面的小数据集中,我想在x轴上绘制日期值。我希望对数据框中存在的所有日期标记进行标记。目前,它只标记了3个随机滴答声。我可以将该列更改为一个因子,但将其作为日期意味着x轴的间隔取决于点之间的时间间隔。到目前为止,我能找到的唯一答案是那些每个月都想展示的问题,或者至少是间隔相等的问题。我只想显示数据集中的值。多谢各位 数据: dput(melt) structure(list(Sample = structure(c(16023, 16023, 16027, 16027, 16031, 160

在下面的小数据集中,我想在x轴上绘制日期值。我希望对数据框中存在的所有日期标记进行标记。目前,它只标记了3个随机滴答声。我可以将该列更改为一个因子,但将其作为日期意味着x轴的间隔取决于点之间的时间间隔。到目前为止,我能找到的唯一答案是那些每个月都想展示的问题,或者至少是间隔相等的问题。我只想显示数据集中的值。多谢各位

数据:

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()
代码:

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()
绘图:

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

您可以在中断时提供
melt$Sample
。您可能还希望旋转轴标签以避免重叠

ggplot(melt, aes(x = Sample, y = value, colour = variable, group = variable)) +
  facet_wrap(~Treatment) +
  geom_point() +
  geom_line() + 
  scale_x_date(breaks = melt$Sample) + 
  theme(axis.text.x = element_text(angle = 90))

对不起,我没听清楚。做aes(x=因子(样本))时出现了什么问题…?@RonakShah df中的时间间隔不是均匀分布的。大多数间隔为4天,一些间隔为3天,一个间隔为6天。在日期格式中,x轴的空间反映了这一点。在绘图中,看到第二个最后一点和最后一个点之间的距离是如何更长的吗?当一个因子时,它们之间的距离都相同。在短时间内被2分钟击败不同的答案有相同的作用:
scale\u x\u date(breaks=unique(melt$Sample))+theme(axis.text.x=element\u text(angle=45,hjust=1))