Introduction
This article describes how to go from a table like this:
To a stacked column chart which compares against the previous period:
Requirements
- A table with at least two columns and at least one row.
Method
-
Create a table with the Nominal - Multi by date.
-
Set the statistics testing to compare to previous period. To do so:
-
Select the table
-
In the Object Inspector, click the Properties tab and from the Significance menu, select Advanced > Test Type.
-
From the Date: menu, select Compare to previous period
-
- Use R to reshape the table. There are two ways to do this:
Using the Statistical Assumptions Attitributes
- Click Calculation > Custom Code right
- Copy and paste the following R program into the R CODE box (you will need to change the variable names to match the ones in your file).
# Getting table. Note that this is a four dimensional array.
x = table.Brand.attitude.by.Interview.Date.5
dims = dim(x)
n.brands = dims[1]
n.statements = dims[2]
n.periods = dims[3]
brand.names = dimnames(x)[[1]]
# Getting stat testing information. Note that this appears as a data frame.
# The stat testing is stored in a data frame, which is structured
# so that the first rows in the data frame represent the first row of the table
# (that is, it is storing the stat testing information according to the rows
# in the table that contains the percentages)
# By happy coincidence in this case it is already in the same order that we will
# want so that it matches up with them modifications that we will make to the
# table containing the percentages
stat.testing.info = attr(x, "QStatisticsTestingInfo")
# Rearrangin the percentages to a format that is liked by the visualization
# swapping around dimensions
x = aperm(x, c(3, 2, 1))
# Replacing a 3D array with a 2D array, by subscripting and then splicing by row
library(abind)
x = abind(x[,,1], x[,,2], x[,,3], along = 1)
# Updating column names
rownames(x) = paste(rep(brand.names, rep(n.periods, n.brands)),
rownames(x)[1:n.periods])
# Appending the statistic name, so Displayr recognizes the data in the table
attr(x, "statistic") <- "Column %"
# Appending the stat testing
attr(x, "QStatisticsTestingInfo") = stat.testing.info
x
rearranged = x - Click Calculate
- From the Visualization menu, select Column > Stacked Column
- Click Inputs > DATA SOURCE: > Output in Pages
- Select the output from your R program:
The results are as follows:
Using the Z-Statisic and Annotations in the Visualization
- Click Calculation > Custom Code right
- Copy and paste the following R program into the R CODE box (you will need to change the variable names to match the ones in your file).
# Getting table. Note that this is a four dimensional array.
x = table.Brand.attitude.by.Interview.Date.6
dims = dim(x)[1:3]# Ignoring last dimension as unneeded
n.brands = dims[1]
n.periods = dims[3]
brand.names = dimnames(x)[[1]]
# swapping around dimensions
x = aperm(x, c(3, 2, 1, 4))
# Replacing a four dimensional array with a 3 dimensional array by
# subscripting and then splicing together by row
library(abind)
x = abind(x[,,1, ], x[,,2, ], x[,,3, ], along = 1)
# Updating column names
n.months = dim(x)
rep(n.periods, n.brands)
rownames(x) = paste(rep(brand.names, rep(n.periods, n.brands)),
rownames(x)[1:n.periods])
rearranged.with.z = x
Click Calculate - From the Visualization menu, select Column > Stacked Column
- Click Inputs > DATA SOURCE: > Output in Pages
- Select the output from your R program:
The results are as follows:
Next
How to Create a Stacked Column Chart
Comments
0 comments
Article is closed for comments.