gpt4 book ai didi

r - geom_col 以错误的方式绘制数据

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

我对 ggplot 有疑问。数据:

df <- structure(list(date = structure(c(1499050800, 1499054400, 1499058000, 
1499061600, 1499065200, 1499068800, 1499072400, 1499076000, 1499079600,
1499083200, 1499086800, 1499090400, 1499094000, 1499097600, 1499101200,
1499104800, 1499108400, 1499112000, 1499115600, 1499119200, 1499122800,
1499126400, 1499130000, 1499133600, 1499137200, 1499140800, 1499144400,
1499144400, 1499148000, 1499151600, 1499155200, 1499158800, 1499162400,
1499166000), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
output = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 0, 0, 0, 0, 0)), .Names = c("date",
"output"), row.names = c(NA, -34L), class = c("tbl_df", "tbl",
"data.frame"))

剧情:

ggplot()+
geom_col(data = df, aes(x = date, y = output))

5 的值绘制为 8。

最佳答案

因为您同时有两个观察值 (5+4=9)。试试这个:

ggplot(data = df, aes(x = date, y = output))+
geom_bar(stat="identity", position = "dodge")

编辑: 或者按照@MbrMbr 在评论中的建议:

ggplot(data = df, aes(x = date, y = output))+
geom_col(position = "dodge")

关于r - geom_col 以错误的方式绘制数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44904888/

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