我无法立即在直方图中看到线条

I can not see the line in my histogram immediatly

我有个小问题。

绘制带直线的直方图时,直线不会立即显示。我必须绘制它 2 次,然后切换回第一个图才能看到实际的线。

hist(df$column, 
     col = "lightgreen", 
     main = "The BMI of the players",
     xlab = "BMI", 
     ylab = "Amount of players", 
     xlim=c(20, 30),
     breaks = 20, 
     freq=FALSE) # close hist
lines(density(df$column), col="blue", lwd=2)) # lines is a different command

所以 运行 代码并看到这个:

在运行第二次使用它之后,我得到了相同的情节。但是,当我单击箭头查看我以前的情节时,我首先看到了我想要的情节(带线的那个!)

有人知道我是如何立即得到直方图的吗

非常感谢您!

如果您在调用 hist 时调用 lineshist 将绘制一个图,而 lines 将在之前的图上添加一条线,因为他们是同时被调用的。

尝试:

hist(df$column, col = "lightgreen", breaks = 20)
lines(density(df$column), col = "blue", lwd = 2)

直接在情节上得到它

像这样

  hist(df$column, 
         col = "lightgreen", 
         main = "The BMI of the players",
         xlab = "BMI", 
         ylab = "Amount of players", 
         xlim=c(20, 30),
         breaks = 20, 
         freq=FALSE) # close hist
  lines(density(df$column), col="blue", lwd=2)) # lines is a different command