Colors are a very useful way to enrich your visualization. In this recipe, you will learn how to add information to your visualization by selecting Dimension and adding it to Color, which is present in the Marks card.
Adding color
Getting ready
Connect to your local copy of Baby_names.csv and open a blank worksheet.
How to do it...
- Drag and drop State from Dimensions into the Columns shelf.
- Drag and drop Frequency from Measures into the Rows shelf.
- Drag and drop Name into the Filter shelf.
- In the Filter[Name] window, in the General tab, make sure Select from list is selected.
- Click on None to deselect all values.
- In the search bar at the top of the list, start typing soph.
- Tableau will show the results that start with those letters, such as Sophia and Sophie. Select both values:
- Click on OK.
- Drag and drop Frequency to Label in the Marks card.
- We have now created a chart with the summed total frequency of the names Sophie and Sophia per State. But, what if we wanted to know which of the two names is more popular in which state? We will achieve that by adding Name to Color in the Marks card.
- Drag and drop Name from Dimensions onto Color in the Marks card:
How it works...
When you add a discrete dimension (Name) to Color, Tableau disaggregates the measure you are using, Frequency, by the categories of Name, and assigns each category a different color. Since we filtered out all names except for Sophia and Sophie, only those two colors appeared in the chart. It's also possible, and often useful, to add a measure to Color. In that case, the value measure will be represented by a color gradient. For an example of adding a measure to Color, you can refer to the Creating a map with a color gradient recipe.
There's more...
It’s possible to customize the colors in your view by performing the following steps:
- Click on Color in the Marks card, and then click on Edit Colors…:
- In the Edit Colors[Name] window that opens, you can select a color palette from the drop-down menu that appears and click on the Assign Palette button. This will assign colors from the palette that you chose to the categories of your dimension. You can also manually assign specific colors to a category by selecting it in the Select Data Item pane, and by clicking on the desired color on the right-hand side:
- When you are satisfied with the colors, click OK to exit. Note that this will only affect the colors in the particular view you created.
- You can also hardcode a color palette for a specific measure or dimension. Hover over the field pill under Measures or Dimensions and click on the white arrow that appears on it. In the drop-down menu, navigate to Default Properties | Color...:
This will launch the Edit Colors window, where you can choose the color palette. However, once you assign your desired color palette to a field this way, it will be used by default every time you add this field to Color in a view.
See also
- For more information on color palettes, see the Tableau Help page at https://onlinehelp.tableau.com/current/pro/desktop/en-us/viewparts_marks_markproperties_color.html