gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 11:20:29 27 4
gpt4 key购买 nike

在下面的小数据集中,我想在 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()

剧情:

enter image description here

最佳答案

您可以提供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))

enter image description here

关于r - 在 ggplot x 轴上显示所有日期值 - R,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51604367/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com