对数刻度在 Y 轴上不起作用

时间:2021-07-24 21:44:03

标签: r ggplot2

enter image description here

enter image description here

enter image description here

plot <- ggplot(Intel, aes(x = Date, y = log(Adj.Close))) +
  geom_line(aes(size = Volume)) + 
  scale_y_log10() +
  scale_x_date(date_breaks = "1 year", labels = date_format("%Y"))

我的图表应该看起来像第一张图片,但看起来像第二张。我不知道为什么 y 轴不会调整。我不了解对数比例,但需要在这里使用 log 10。有人能告诉我为什么图表看起来如此不同以及如何解决吗?

1 个答案:

答案 0 :(得分:1)

为了确保我们可能需要 mcve,但我强烈怀疑您应该在 y = Adj.Close 规范中使用 y = log(Adj.Close) 而不是 mapping(第二个参数ggplot,带有aes()的东西)。 scale_y_log10() 语句应该处理所有事情,所以我认为您有效地双重记录了您的数据。