I want to plot the results of throwing a dice in a bar chart using ggplot.
import numpy
import ggplot
import pandas
frame = pandas.DataFrame()
for i in range(6):
frame.loc[i, 'pips'] = i+1
rand = numpy.random.random_integers(1, 6, 100)
for i in range(len(count)):
frame.loc[i, 'events'] = numpy.sum(rand == i+1)
frame['propability'] = frame.events / frame.events.sum()
ggplot.ggplot(ggplot.aes(x='pips', weight='events'), frame) + ggplot.geom_bar()
The outcome is
From the examples I expected the plot to
How do I fix these two things?
Use parameters "binwidth", "limits" and "breaks" like this :
ggplot.ggplot(ggplot.aes(x='pips', weight='events'), frame) +
ggplot.geom_bar(binwidth=1) +
ggplot.scale_x_continuous(limits = (1,6), breaks = range(1,7))
Which gives me :