DP8
DP8

Reputation: 55

Simple Histogram plotting issue in R

I just starting to learn R and have this issue in plotting histogram:

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")"

Appreciate any help for beginners.

Upvotes: 0

Views: 390

Answers (1)

Puddlebunk
Puddlebunk

Reputation: 493

This is not the error I get when running your code. I get:

Error in plot.window(xlim, ylim, "", ...) : invalid 'xlim' value

This is because you used "max" for your end value which is not defined in this case. Try picking the value you want x to end at or just let the hist function pick for you.

simply remove the "xlim(1,max)" completely and it will work.

Upvotes: 1

Related Questions