“绘制ggplot时尚未调用plot.new”错误

问题描述 投票:0回答:1

为什么会这样/如何解决这个问题? iv阅读了有关此错误的其他一些条目,但仍然感到困惑,特别是因为当我运行下面的代码时,如果不使用粗体部分,它可以很好地运行,但是如果包含了粗体部分,则会出现此错误。

代码:

ggplot(diamonds, aes(x = price)) + geom_histogram(binwidth = 500) + 
axis(side = 1, at = seq(0, 20000, by = 500))

错误:

Error in axis(side = 1, at = seq(0, 20000, by = 500)) : 
  plot.new has not been called yet
r ggplot2 axis
1个回答
1
投票

axis是图形包而非ggplot的一部分。因此,axis正在寻找plot而不是ggplot

© www.soinside.com 2019 - 2024. All rights reserved.