【发布时间】:2020-04-06 10:24:16
【问题描述】:
我在函数geom_col() 中遇到了问题。如果我的 x 值相距足够大,它似乎工作正常,但如果它们“接近”,我的情节不会按预期显示。请参见下面的示例。
在类似的现有issue中,建议手动设置width,但这并不能解决问题。
此外,人们应该期望第一个和第二个情节以相同的方式工作。但是在第二个图中,默认设置似乎改变了轴
这是一个错误吗?还是我错过了一个选项?
# library(ggplot2)
# plot that does work
df <- data.frame(x = c(1,2,3,5,6), y = c(45,45,45,45,45))
ggplot(df, aes(x = x, y = y)) + geom_col()
# plot that does not work (only different numbers)
df <- data.frame(x = c(0.9,0.91,0.92,1.0,1.01), y = c(45,45,45,45,45))
ggplot(df, aes(x = x, y = y)) + geom_col()
# plot that still does not work, with manual setting of width (you can try different options)
ggplot(df, aes(x = x, y = y)) + geom_col(width = 0.05)
# plot showing that there are at least 5 seperate bars, only I expect y to be the height of the bar and x to be the groups
ggplot(df, aes(x = x, y = y)) + geom_col(position = 'dodge2', colour = "black")
【问题讨论】: