Reputation: 1246
I am trying to plot simple histogram in R. I have an integer vector and I want to draw a histogram with one column per each value.
test_data = c(1,1,1,2,2,3,3,4)
hist(test_data)
But I get this
Please tell me whether it is possible to get the same result as I have in Python?
import matplotlib.pyplot as plt
test_data = [1,1,1,2,2,3,3,4]
plt.hist(test_data)
plt.show()
Upvotes: 0
Views: 773
Reputation: 1698
You can use the nclass
or breaks
argument to adjust the number of bins.
test_data = c(1,1,1,2,2,3,3,4)
hist(test_data,breaks=5)
hist(test_data,nclass=5)
In fact it is the same thing for python. The argument is bins
. The default value is 10 (according to this page)
So if you modify it, we will get a different plot
import matplotlib.pyplot as plt
test_data = [1,1,1,2,2,3,3,4]
plt.hist(test_data,bins=4)
plt.show()
you get
Upvotes: 1
Reputation: 4169
You could us the barplot and table functions
barplot(table(test_data))
Upvotes: 1