1
$\begingroup$
Age     Size of Kidney
0-20     8.5
20-40    9.2
40-60    10.4
60-80    9.3
80-100   8.9

The above data gives the average size of the kidney for the people of age groups given in the fixed interval of age groups. How to plot the above data using Mathematica in Histogram?

$\endgroup$
  • $\begingroup$ This doesn't sound like a Histrogram, because you are not providing the underlying data. Do you just want a BarChart with five different bars? $\endgroup$ – Rashid May 5 '16 at 5:51
4
$\begingroup$

This doesn't sound like an application for Histogram, because you are not providing the underlying data.

It sounds like you are looking for a labeled bar chart. You can achieve this using BarChart and the ChartLabels options. For example:

BarChart[{8.5, 9.2, 10.4, 9.3, 8.9}, ChartLabels -> {"0-20", "20-40", "40-60", "60-80", "80-100"}, AxesLabel -> {"Age Range", "Average Height"}]

You can also use associations where the keys are labels associated with the values. I find this easier to enter and read. For example,

BarChart[<|"0-20" -> 8.5, "20-40" -> 9.2, "40-60" -> 10.4, "60-80" -> 9.3, "80-100" -> 8.9|>, ChartLabels -> Automatic, AxesLabel -> {"Age Range", "Average Height"}]

In either case, you get something like this:

enter image description here

$\endgroup$
  • $\begingroup$ Thanks. One query, How can I add different colors for different bars and join the mid points of the top of every bars to form a curve. Thanks... $\endgroup$ – Roshan Shrestha May 8 '16 at 6:06
  • 1
    $\begingroup$ @RoshanShrestha, use the ChartStyle and Joined options of BarChart; e.g., add ChartStyle -> {Red, Green, Blue, Yellow, Cyan}, Joined->Automatic in BarChart[...]. $\endgroup$ – kglr May 8 '16 at 9:31
  • $\begingroup$ Thanks, Also, by default, there is spacing between bars, Can we remove spaces between bars, so that they are joined ? $\endgroup$ – Roshan Shrestha May 8 '16 at 11:22
  • $\begingroup$ I used BarSpacing->None, but the first bar is still not joined with the y-axis. $\endgroup$ – Roshan Shrestha May 8 '16 at 11:38
  • 1
    $\begingroup$ @RoshanShrestha, try AxesOrigin -> {.5, 0}. $\endgroup$ – kglr May 8 '16 at 11:58
2
$\begingroup$

BarChart is the right approach to view this kind of data. If you have to use Histogram for some reason, here is how you can use it

heights = {8.5, 9.2, 10.4, 9.3, 8.9};
labels = {"0-20", "20-40", "40-60", "60-80", "80-100"};

hist = Histogram[{1}, {Range[0, 100, 20]}, (heights &), 
  ChartStyle -> 1, Ticks -> {Thread[{Range[10, 100, 20], labels}], Automatic}, 
  Epilog -> ListLinePlot[heights, DataRange -> {10, 90}, PlotStyle -> {Red, Thick}][[1]]]

Mathematica graphics

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.