The default correspondence analysis charts in Q are two-dimensional scatterplots (scroll down to see an example). However, you can create a three-dimensional plot by writing a small amount of code. This post will demonstrate how!

## The data

In this post I use a table of the following Pick Any - Grid.

## Correspondence analysis

To create a correspondence analysis plot in Q, follow these steps:

1. Create a table. With a grid like this, this is done by creating a SUMMARY table. However, you can also create a crosstab.
2. Select Create > Dimension Reduction > Correspondence Analysis of a Table.
3. Select the table to be analyzed in the Input table(s) field on the right of the screen.
4. Check the Automatic option at the top-right of the screen.

You will end up with a visualization like the one here. Note that this plot explains 65% + 21% = 86% of the variance that can be explained by correspondence analysis. Fourteen percent is not shown. This fourteen percent may contain interesting insights, and one way to see if it does is to plot a three-dimensional labeled scatterplot.

## Interactive 3D scatterplot

We now need to write a bit of code - but don't worry! We just need to cut and paste and change a few characters.

1. Go to Create > R Output.
2. Copy and paste in the code shown after point 4 on this page.
3. Replace my.ca with the name of your correspondence analysis. If you right-click on the correspondence analysis in the report tree and select Reference name you will find the name (you can modify the name if you wish).
4. Check the Automatic option at the top right of the screen.
```
rc = my.ca\$row.coordinates
cc = my.ca\$column.coordinates
library(plotly)
p = plot_ly()
p = add_trace(p, x = rc[,1], y = rc[,2], z = rc[,3],
mode = 'text', text = rownames(rc),
textfont = list(color = "red"), showlegend = FALSE)
p = add_trace(p, x = cc[,1], y = cc[,2], z = cc[,3],
mode = "text", text = rownames(cc),
textfont = list(color = "blue"), showlegend = FALSE)
p <- config(p, displayModeBar = FALSE)
p <- layout(p, scene = list(xaxis = list(title = colnames(rc)[1]),
yaxis = list(title = colnames(rc)[2]),
zaxis = list(title = colnames(rc)[3]),
aspectmode = "data"),
margin = list(l = 0, r = 0, b = 0, t = 0))