This article describes how to hook up visualizations to plot subsections of a table using point and click or R code. Using point and click within the Data field automatically converts that selection to R code, which is embedded as an inline calculation in the visualization. You can also modify this code directly if you wish. This article covers how to:
- Method 1 - Select the data to plot then make the visualization
- Method 2 - Hook up an existing visualization to a subsection of a table
- Method 3 - Copy and paste a reference to your selection as the data for a visualization
- Method 4 - Manually type in or edit an R code reference as the Data Source
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.
Note, you can also use rules to modify the table to only show the data you want to plot if needed.
Requirements
- A Displayr document
- A basic table that you would like to use as an input, such as native drag and drop tables and basic R tables that do not have special formatting (including CreateCustomTable and Table with Custom Formatting visualization).
- Familiarity with Displayr's point-and-click R code interface - How to Use Point and Click Inside R Code. That is to select a whole column, you only need to select the column header, and vice versa with rows. Otherwise, you can also select individual cells of data in the table.
- If manually writing R code, see How to Reference Different Items in Your Document in R.
Method 1 - Select the data to plot then make the visualization
This method is only available to tables on Pages and not directly outputs in the Report tree.
- On your existing table, select the subsection you want to plot (i.e., column header(s), row header(s), or individual cells). The Feminine column header is selected below to plot the entire column.
- From either the object inspector (if you want to nest the table underneath) or toolbar (if you want to see both the table and visualization), select Visualization > Bar > Bar or the chart you wish.
- Click and position the visualization as desired on the Page. Notice the visualization's object inspector Data Source is R code referencing the first column inside the brackets.
Method 2 - Hook up an existing visualization to a subsection of a table
This method is only available to tables on Pages and not outputs directly in the Report tree.
- On the same page as the table you want to use as input, either use an existing visualization on the page or use the toolbar > Visualization menu to insert one.
- In the object inspector of the visualization, click into the Data Source > Data field and delete any text there currently.
- On your existing table, select the subsection you want to plot (i.e., column header(s), row header(s), or individual cells). The Feminine column header is selected below to plot the entire column.
- The R code for your selection is automatically put into the Data field. Hit the Enter key to have the visualization plot the data.
Method 3 - Copy and paste a reference to your selection as the data for a visualization
This method can be used with all visualizations and tables on Pages and as outputs in the Report tree.
- On your existing table, select the subsection you want to plot (i.e., column header(s), row header(s), or individual cells), click Ctrl+C or right click > Copy to copy the reference to those cells. The Feminine column header is selected below to plot the entire column.
- In the object inspector of the visualization, click into the Data Source > Data field and delete any text there currently.
- Hit Ctrl+V to automatically insert the R code for your selection into the Data field. Hit the Enter key to have the visualization plot the data.
Method 4 - Manually type in or edit an R code reference as the Data Source
This method can be used with all visualizations and tables on Pages and as outputs in the Report tree.
- Click on the visualization, and in the object inspector, click into the Data Source > Data field.
- If your Data field was already R code, you can edit it directly after it shows as being highlighted:
- Otherwise, in the dropdown select Enter a calculation or value.
- Type in the R code for the reference you want to plot on the table. For multi-column/row tables, this will be the
tableName[rows, columns]where rows and columns can be blank (for all) or one or more numbers or headers. In our example of plotting the Feminine column, you could use any of the examples below:table.q5[,1]table.q5[,"Feminine"] - When done entering/editing the code, hit the Enter key. Your visualization will automatically plot the data.
If you are using a combo box or other calculation to subset the table in R code, you can instead use the Select Rows to show by or Select Columns to show by fields on the Row/Column Manipulation sections, see How to Select Which Rows or Columns to Show in a Visualization Based on a Control Box Selection.
Next
How to Use Point and Click Inside R Code
Creating and Modifying Visualizations
UPCOMING WEBINAR: 10 Market Research Predictions Over the Next 4 Years