简体   繁体   English

R中的简单直方图绘制问题

[英]Simple Histogram plotting issue in R

I just starting to learn R and have this issue in plotting histogram: 我刚开始学习R并在绘制直方图时遇到这个问题:

I did sample data set below: 我做了下面的示例数据集:

B <- c(2, 4, 5, 7, 12, 14, 16)  
hist(B) # this plots histogram

But when additional parameters were added like 但是当添加其他参数时

hist(B, col = "red", breaks=6, xlim=c(0, max), main="My Histogram", las=2, xlab="Values")

Here's the error I'm getting when adding params: 这是添加参数时出现的错误:

xlab = "Values") Error: unexpected ')' in "xlab = "Values")" xlab =“ Values”)错误:“ xlab =” Values“)”中出现意外的')'

Appreciate any help for beginners. 感谢初学者的帮助。

This is not the error I get when running your code. 这不是我在运行代码时遇到的错误。 I get: 我得到:

Error in plot.window(xlim, ylim, "", ...) : invalid 'xlim' value plot.window(xlim,ylim,“”,...)中的错误:无效的'xlim'值

This is because you used "max" for your end value which is not defined in this case. 这是因为您为最终值使用了“ max”(在这种情况下未定义)。 Try picking the value you want x to end at or just let the hist function pick for you. 尝试选择您希望x结束的值,或者让hist函数为您选择。

simply remove the "xlim(1,max)" completely and it will work. 只需完全删除“ xlim(1,max)”即可使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM