cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
mvanderaa1
Level IV

scatterplot with histogram next to the axis

I came across this earlier post where using fit Y by X was suggested to plot histograms besides the axes for a scatter plot.

This has multiple drawbacks however, taking the iris.jmp datatable as an example

- you cannot show split the histogram per group (species column)

- you cannot switch the histogram to kernel density

mvanderaa1_1-1791462503182.png

 

a much nicer visualization is possible in ggplot2. Can below visualization be produced in JMP?

 

mvanderaa1_0-1791462043893.png

 

1 ACCEPTED SOLUTION

Accepted Solutions

Re: scatterplot with histogram next to the axis

I'm sure there are other ways to do this, but here is how I did it. I start by making four graphs instead of one, using each axis twice, like this: 

christianz_3-1791466749266.png

If you click the points element now, it will remove all graphs and leave only a "blank canvas", like this: 

christianz_4-1791466813466.png

Next, drag and drop the desired graph element into each quadrant. Points in the bottom left, histograms in the top left and bottom right (it looks wrong, but we will fix it in the next step): 

christianz_5-1791466919281.png

Now for the "trick": we need to "ignore" one of the axes in each histogram, like this: 

christianz_6-1791467014547.png  christianz_7-1791467043633.png

At this point, the graph should look like this. We are almost there. 

christianz_8-1791467091270.png

Now it's just a matter of resizing the axes, hiding some unwanted labels, and adjusting the style to your liking: 

christianz_9-1791467253290.png

 

 

View solution in original post

6 REPLIES 6

Re: scatterplot with histogram next to the axis

Yes, this can be done in Graph Builder. Here's how it looks with JMP's default style and color settings. With some customization I think you could get something quite similar to your example above. 

christianz_1-1791466577187.png

 

Here is a script that will generate the plot above, if you have the Iris dataset open: 

View more...
Graph Builder(
	Size( 568, 469 ),
	Show Control Panel( 0 ),
	Variables(
		X( :Sepal length ),
		X( :Sepal length ),
		Y( :Sepal width ),
		Y( :Sepal width ),
		Overlay( :Species )
	),
	Relative Sizes( "X", [303 75] ),
	Relative Sizes( "Y", [72 246] ),
	Elements(
		Position( 1, 1 ),
		Histogram( X, Legend( 13 ), Histogram Style( "Polygon" ) )
	),
	Elements( Position( 1, 2 ), Points( X, Y, Legend( 5 ) ) ),
	Elements( Position( 2, 1 ) ),
	Elements(
		Position( 2, 2 ),
		Histogram( Y, Legend( 17 ), Histogram Style( "Polygon" ) )
	),
	SendToReport(
		Dispatch( {}, "Sepal length", ScaleBox( 2 ),
			{Label Row(
				{Automatic Tick Marks( 0 ), Show Major Labels( 0 ),
				Show Major Ticks( 0 ), Show Minor Ticks( 0 )}
			)}
		),
		Dispatch( {}, "Sepal width", ScaleBox,
			{Label Row(
				{Automatic Tick Marks( 0 ), Show Major Labels( 0 ),
				Show Major Ticks( 0 ), Show Minor Ticks( 0 )}
			)}
		),
		Dispatch( {}, "Sepal length", TextEditBox, {Set Text( "" )} ),
		Dispatch( {}, "", AxisBox, {Add Axis Label( "Sepal lengthz" )} ),
		Dispatch( {}, "Sepal lengthz", TextEditBox, {Set Text( "Sepal length" )} ),
		Dispatch( {}, "Sepal width", TextEditBox, {Set Text( "" )} ),
		Dispatch( {}, "Sepal length", TextEditBox, {Set Text( "" )} ),
		Dispatch( {}, "400", LegendBox,
			{Legend Position( {13, [-1, -1, -1], 5, [0, 1, 2], 17, [-3, -3, -3]} )}
		)
	)
);

 

mvanderaa1
Level IV

Re: scatterplot with histogram next to the axis

Hi Christian, thank you for your fast reply.

This looks very nice indeed for this specific scatter plot.

But what if I broaden the question for any dataset? How would I go about creating this kind of graph in the future?

Re: scatterplot with histogram next to the axis

I'm sure there are other ways to do this, but here is how I did it. I start by making four graphs instead of one, using each axis twice, like this: 

christianz_3-1791466749266.png

If you click the points element now, it will remove all graphs and leave only a "blank canvas", like this: 

christianz_4-1791466813466.png

Next, drag and drop the desired graph element into each quadrant. Points in the bottom left, histograms in the top left and bottom right (it looks wrong, but we will fix it in the next step): 

christianz_5-1791466919281.png

Now for the "trick": we need to "ignore" one of the axes in each histogram, like this: 

christianz_6-1791467014547.png  christianz_7-1791467043633.png

At this point, the graph should look like this. We are almost there. 

christianz_8-1791467091270.png

Now it's just a matter of resizing the axes, hiding some unwanted labels, and adjusting the style to your liking: 

christianz_9-1791467253290.png

 

 

mvanderaa1
Level IV

Re: scatterplot with histogram next to the axis

Hi Christian, I'll accept this as a solution, although it would be really nice to have this functionality integrated nicely in JMP. Do you know if there's a feature request already?

MathStatChem
Level VII

Re: scatterplot with histogram next to the axis

You can do this

MathStatChem_0-1791466765474.png

It is a little tricky to do with the UI, but it is possible.  

MathStatChem
Level VII

Re: scatterplot with histogram next to the axis

Recommended Articles