4

I'm learning R and I'm trying out the hist() histogram function. My code is here(and pasted below), and when I run it, the axes A) Do not connect at the origin, and B) they don't extend far enough for the dataset. I've looked and haven't found anything, the properties xlim, ylim, axes=FALSE, none of these solutions work.

bluegill = read.table(file="lab2.csv", header="true", sep=",")
attach(bluegill)

hist(Length, main="", xlab="Length (mm)", ylab="Number of individuals", col="gray")

and then this is the resulting chart, the max length is 220 in the data set, and the x axis only goes to 200.

enter image description here

user20650
  • 24,654
  • 5
  • 56
  • 91

1 Answers1

2

A simple solution could be this:

bluegill = read.table(file="lab2.csv", header="true", sep=",")
attach(bluegill)

hist(Length, main="", xlab="Length (mm)", ylab="Number of individuals", col="gray", xaxt = "n") ##no x axis

Please notice the new option that has been added, xaxt = "n", which removes the x axis completely. You could then add the x axis late with another command. e.g.

axis(1, at = seq(0, 200, 20))
  • The first option is 1, which means x axis.
  • The second option stands for the points that will be shown in the plot (excuse my English).
codingEnthusiast
  • 3,800
  • 2
  • 25
  • 37