Skip to main content Link Search Menu Expand Document (external link)

Procedure 4: Quickly Creating a Histogram with qplot()

The qplot() histogram bears resemblance to the hist() function, being called almost identically:

qplot(Boston$PerCapitaCrimeRate)

img.png

Run the line of script to console:

img_1.png

It can be seen that an error message has been created suggesting that the bin width is too wide, which is clearly the case in the plot being written out with a very wide scale:

img_2.png

Specifying the binwidth parameter of the qplot function solves the issue of their being too many bins by widening the size of the bins:

qplot(Boston$PerCapitaCrimeRate,binwidth=10)

img_3.png

Run the line of script to console:

img_4.png

It can be seen that a histogram has been plotted in RStudio, with fewer bars owing to the distances for the bars being wider:

img_5.png


Jube™. © Jube Holdings Limited 2022 to present.