A histogram with a bar for each frequency value


I have a data of 100 rolls of two dice, which can take on 11 values -> {2,3,4,5,6,7,8,9,10,11,12}

How do I create a histogram in R that would show all 11 of them, each as it's own bar with a label for each one of them.

hist(data$X1,breaks=c(1,2,3,4,5,6,7,8,9,10,11,12,13),col = "lightblue",xlab="Sum of a roll")

Only gives 10 bars.


I did something approximate with moving breaks 0.5 up like so:



Histograms can also be plotted with ggplot. Using @flodel's data:

dd = data.frame(table(sums)) ggplot(dd)+geom_bar(aes(x=sums, y=Freq), stat='identity')

<img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/xtx9n.png" data-original="https://i.stack.imgur.com/xtx9n.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" />


You could just do a barplot of the frequency table:

num.dices <- 2L num.rolls <- 100000L outcomes <- matrix(sample(1:6, num.dices * num.rolls, replace = TRUE), nrow = num.rolls, ncol = num.dices) sums <- rowSums(outcomes) barplot(table(sums))

<img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/AHWgm.png" data-original="https://i.stack.imgur.com/AHWgm.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" />


  • [] is not identical to [] [duplicate]
  • How to fit a cylinder to scattered 3D XYZ point data in MATLAB?
  • Access to directory denied when running ASP.Net MVC site(4.0) in release mode on IIS 7.5 (Shared Hos
  • Determine illuminance from RGB image
  • Interpolating 2D Matrix Data
  • Displaying MongoDB Documents with HTML
  • How do I get an image w/ the exact size in pixels, when using bbox_inches='tight' in matpl
  • Moon orbit in relation to sun
  • Interlocked.Increment vs lock in debug vs release mode
  • Web API Basic Auth inside an MVC app with Identity Auth
  • Haskell: List Created Evaluating List Elements
  • How to produce a Code 39 that can be reliably read after faxing
  • Windows/C# system-level sequential number generator?
  • Default CUDA addition rounding mode between cuda 5.0 and 7.5
  • Where to put clearQueue in jQuery code
  • How to get value of the slider, when touchend or mouseup events are used?
  • How can I merge my files when the folder structure has changed using Borland StarTeam?
  • What's an elegant way of accessing parent controller's member from child controller?
  • Whats the right place for testhelper-classes? (phpunit/best practise)
  • Struct pointer casts
  • MongoDB GeoJSON “Can't extract geo keys from object, malformed geometry?” when inserting type P
  • RabbitMQ java client stops consuming messages
  • Highcharts - Column chart with empty columns for date in x-axis
  • Calculating ratio of reciprocated ties for each node in igraph
  • How to create CGPath from a SKSpriteNode in SWIFT
  • R convert summary result (statistics with all dataframe columns) into dataframe
  • Linq Merge lists
  • Approximate Order-Preserving Huffman Code
  • Generate random number from custom distribution
  • Tamper-proof configuration files in .NET?
  • Grails calculated field in SQL
  • Mysterious problem with floating point in LISP - time axis generation
  • JSON response opens as a file, but I can't access it with JavaScript
  • Cannot connect to cassandra from Spark
  • Fetching methods from BroadcastReceiver to update UI
  • Is possible to count alias result on mysql
  • How to apply VCL Styles to DLL-based forms in Inno Setup?
  • Symfony2: How to get request parameter
  • GridView Sorting works once only
  • WPF Applying a trigger on binding failure