![Y Axis: Frequency, X axis: Ratio][1]
https://i.stack.imgur.com/Xmg3i.png
Can anyone help me with a suitable syntax to create this kind of a histogram in R? The input data will be the Ratio corresponding to a person and his/her age range. Sample:
Age Ratio
(15-19) 0.97
(65-69) 1.2084
(50-64) 1.3049
and so on.
I’m not sure what these are called, could you mention the name of this kind of histogram as well?
I think you might have the best luck with the ‘ggplot2’ package, and the chart you’re looking for is a “stacked bar chart” and not a histogram.
Setup: Create some sample data.
Plot it: We can just use the ‘qplot’ function here.
Here, we tell the ‘qplot’ function to use the [ratio] data from our [data] data frame and to plot it in a bar chart geometry. The data should be split and colored by the [age] (
fill=age), and each bar should be 0.1 wide. You should be able to adjust this to your needs.