gpt4 book ai didi

r - R中日期直方图的轴颜色

转载 作者:行者123 更新时间:2023-12-04 13:54:52 24 4
gpt4 key购买 nike

我已经成功地使用日期字段创建了直方图。

hist(df.sat$created_at, breaks="hours", freq=T, xlab="Time", 
main="Sat Volume")

我的问题是,当我仅想使用条形图时,当尝试使用 col="red"填充条形图时,两个条形图和x/y轴都变为红色。什么是最好的方式只填写酒吧?

以下是一些数据:
    > dput(df.sat$created_at[sample(c(1:9000), 50)])
structure(list(sec = c(41, 3, 13, 11, 49, 55, 19, 21, 6, 15,
54, 45, 45, 39, 50, 27, 35, 25, 22, 35, 42, 31, 45, 29, 1, 3,
8, 47, 38, 2, 13, 29, 34, 42, 15, 19, 3, 39, 41, 12, 34, 50,
15, 27, 0, 29, 47, 26, 21, 5), min = c(46L, 38L, 4L, 35L, 26L,
56L, 9L, 52L, 51L, 15L, 49L, 3L, 41L, 59L, 30L, 30L, 30L, 53L,
25L, 51L, 23L, 38L, 30L, 3L, 43L, 33L, 36L, 52L, 0L, 21L, 27L,
22L, 51L, 31L, 0L, 37L, 3L, 2L, 12L, 3L, 45L, 13L, 59L, 10L,
11L, 7L, 41L, 21L, 5L, 20L), hour = c(14L, 16L, 18L, 15L, 15L,
16L, 16L, 18L, 18L, 13L, 18L, 16L, 14L, 13L, 16L, 15L, 18L, 17L,
18L, 18L, 16L, 17L, 17L, 19L, 15L, 18L, 17L, 18L, 19L, 17L, 16L,
17L, 18L, 20L, 18L, 15L, 14L, 14L, 18L, 18L, 19L, 19L, 16L, 15L,
17L, 17L, 15L, 17L, 17L, 17L), mday = c(9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L), mon = c(3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L), year = c(111L, 111L, 111L, 111L, 111L, 111L, 111L, 111L,
111L, 111L, 111L, 111L, 111L, 111L, 111L, 111L, 111L, 111L, 111L,
111L, 111L, 111L, 111L, 111L, 111L, 111L, 111L, 111L, 111L, 111L,
111L, 111L, 111L, 111L, 111L, 111L, 111L, 111L, 111L, 111L, 111L,
111L, 111L, 111L, 111L, 111L, 111L, 111L, 111L, 111L), wday = c(6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L), yday = c(98L, 98L, 98L, 98L, 98L, 98L, 98L, 98L, 98L, 98L,
98L, 98L, 98L, 98L, 98L, 98L, 98L, 98L, 98L, 98L, 98L, 98L, 98L,
98L, 98L, 98L, 98L, 98L, 98L, 98L, 98L, 98L, 98L, 98L, 98L, 98L,
98L, 98L, 98L, 98L, 98L, 98L, 98L, 98L, 98L, 98L, 98L, 98L, 98L,
98L), isdst = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L)), .Names = c("sec", "min", "hour", "mday",
"mon", "year", "wday", "yday", "isdst"), class = c("POSIXlt",
"POSIXt"), tzone = c("America/New_York", "EST", "EDT"))

最佳答案

您必须先绘制直方图,然后再绘制轴,以解决该问题:

hist(Data, breaks="hours", freq=T, xlab="Time", col="red",
main="Sat Volume",axes=F)
Axis(Data,col="black",side=1)
axis(2,col="black")

使用通用 Axis()的原因是,它考虑到您的变量是TimeDate类。默认的 axis()没有。

编辑 :

仅供引用,只有在X轴上使用 DateTime类的直方图才能看到此行为。当对条使用填充颜色时,默认的 hist()函数不会更改轴的颜色。

关于r - R中日期直方图的轴颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5649600/

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