为什么会发生这种情况/如何解决此问题?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
>axis
是图形包的一部分,而不是ggplot。所以axis
正在寻找一个plot
而不是一个ggplot
.
尝试
ggplot(diamonds, aes(x = price)) +
geom_histogram(binwidth = 500) +
scale_x_continuous(breaks = seq(0,20000, by = 500))
或在基础图形中
hist(diamonds$price)
axis(side = 1, at = seq(0, 20000, by = 500))