This article describes how to use sub-sections of larger tables and even custom R-based calculations in tables and visualizations.
For example, here we have a table that analyzes respondents' perceptions toward various colas, but we only want to graph a couple of them.
We would like to create a bar chart of the data, but rather than graph the entire table, we would like to create a graph of just the first column labeled Feminine.
Requirements
- A Displayr document
- Familiarity with Displayr's point-and-click R code interface - How to Use Point and Click Inside R Code
- Optional: If programming custom calculations some basic knowledge of programming with R - How to Learn R
Method 1 - Table That is a Subsection of a Larger Table
- From the toolbar, select Table > Paste or Enter Table
- Select an existing table from the DATA SOURCE > Output in 'Pages' dialog. If you don't have a table, you can select the variables you want in the Variables in 'Data' box. You can also click Paste or type data to enter the data from a spreadsheet.
- From the Output in 'Pages' menu, select Enter a Calculation or value.
- In the Output in 'Pages' box type the table name and the rows/columns you want. In this example, we entered table.Brand.attitude[1:3,] which will extract the first 3 rows of the table.
- Type ENTER
This will create a sub-table which just contains the rows pertaining to Coca-Cola products.
Method 2 - A Visualization Based on a Subsection of a Larger Table
- Create the table you want to visualize.
- Select the table, and in the Object Inspector, select Table > Properties > General and take note of the name of the table
- From the toolbar, select Table > Paste or Enter Table
- From the DATA SOURCE > Output in 'Pages' menu, select Enter a calculation or value. (Be sure to take note of the table name in the Output in Pages' box)
- In the Output in 'Pages' box, type the table name and the rows/columns you want. In this example, we entered table.q5[,1] which extracts column 1 ("Feminine") and all rows.
- Click ENTER
The results are as follows: - In the Object Inspector, select OUTPUT > Visualization > Bar > Bar
The results are as follows:
Method 3 - A Visualization Based on a Custom Calculation
- Create the table you want to visualize.
- From the toolbar, select Table > Paste or Enter Table
- From the DATA SOURCE > Output in 'Pages' menu, select Enter a calculation or value.
- To display the difference between column 1 (Feminine) and column 2 (Health Conscious), in the Output in 'Pages' box, we can subtract column 2 from column 1 by typing table.q5.3[,1]-table.q5.3[,2]
The results are as follows: - In the Object Inspector, select OUTPUT > Visualization > Bar > Bar
The results are as follows:
Next
How to Use Point and Click Inside R Code
Creating and Modifying Visualizations
How to Add a Custom Calculation
Calculations in Visualizations