# Create line graph with embedded horizontal histogram

How do I create these kinds of graphs:

with the horizontal histogram counting the number of times the left graphs go through a certain range?

-
"Gemeotric"... *Gnnnhhhh* – Daniel Andersson May 22 '12 at 16:04
hahahaha, yeah. – Jimi May 22 '12 at 16:38
Using R, I would create two plot objects in ggplot2, a line chart and a histogram, then arrange them both on the same plot using grid.arrange(), pushViewport and viewport() then export to a file. But that is not a trivial undertaking, unless you are already an R expert. Otherwise your best bet may be to make two charts in Excel and stitch them together in a graphics application like GIMP or using ImageMagick. If you need to do this kind of thing on a regular basis, it might well be worth getting familiar with ggplot (or one of the other R graphics packages). – SlowLearner May 23 '12 at 3:04
The R code for the 'combining multiple plots into one' ggplot2 approach I just mentioned is given in the ggplot book and can be found right at the bottom of this page: had.co.nz/ggplot2/book/polishing.r – SlowLearner May 23 '12 at 3:11
can't you simply "record" a macro while creating exactly what you want and the alternate the code to do it automaticly in the future? if you have any troubles you are welcome to come back and ask for help... – Dirk Reichel Nov 7 '15 at 21:04

## STEP 1

Create your line chart. Set the Y Axis min and max value. Do not let them be automatic. I set mine to `0` and `250`.

## STEP 2

Create your histogram data. Determine how many bins you want and setup a range for the formulas. I picked 30 bins and so I setup the range `G1:H32`. Row 1 is for the heading, Row 32 is for the max value. Rows 2:31 are for the actual histogram value. `G2` and `G32` are manually entered to be the same as the min & max axis values you set in Step 1. Column H is all the `COUNTIF` functions to calculate how many values fall in each bin. There are fancier ways to do this - like the `FREQUENCY` function - but my method here works and is simple.

## STEP 3

Create your 2D bar chart and format as desired. You may have to set the axis to display in reverse order. I would recommend leaving the axes in place but turning off the tick marks and labels. If you remove it, the plot area will resize and you'll have to manually align it with your line chart. I also reduced the gap between the series but that's mainly a style choice. Edit yours to look like whatever you want. Resize both charts to be the same height and align their top edges.

-