# Create an animated visualization with time series

<div align="left"><figure><img src="https://3015558743-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFEElAdsRIl9DzfMhbRlB%2Fuploads%2F8iAlvj1s2Th85m6IvcG5%2Fbeginner%20banner.png?alt=media&#x26;token=10e8f40a-3632-4920-87c3-6b0dca2a6775" alt="Beginner difficulty banner" width="175"><figcaption></figcaption></figure></div>

## **Context**

As we grow more attuned to the delicate balance of our natural world, understanding the movements of its inhabitants becomes crucial, not just for conservation but for enhancing our data visualization skills. The migration routes of blue whales offer a wealth of data that, when visualized, can inform and inspire protective measures.

This tutorial takes you through a general approach to building animated visualizations using Builder [Time Series Widget](https://academy.carto.com/building-interactive-maps/data-visualization/broken-reference). While we focus on the majestic blue whales of the Eastern Pacific from 1993 to 2003, the techniques you'll learn here can be applied broadly to animate and analyze any kind of temporal geospatial data whose position moves over time.&#x20;

Join us in this tutorial, as we transform raw data into a dynamic map that tells a compelling story over time.

## **Steps To Reproduce**

1. Access the *Maps* from your CARTO Workspace using the Navigation menu and create a "New map".

<figure><img src="https://3015558743-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFEElAdsRIl9DzfMhbRlB%2Fuploads%2F3X1OmhFpMbNgKwFjiucs%2Fimage.png?alt=media&#x26;token=0ff6215c-86ec-472b-8457-a07adeb66e73" alt=""><figcaption></figcaption></figure>

2. Let's add the blue whales point location as the first data source.&#x20;
   * Select the A*dd source from* button at the bottom left on the page.&#x20;
   * Click on the *CARTO Data Warehouse* connection.
   * Select *Type your own query*.
   * Click on the *Add Source button*.

<figure><img src="https://3015558743-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFEElAdsRIl9DzfMhbRlB%2Fuploads%2FESUVFIxegkWhkRYkbCKS%2Fimage.png?alt=media&#x26;token=cf814a66-6e03-467d-8dcd-d37af8791c1e" alt=""><figcaption></figcaption></figure>

The SQL Editor panel will be opened.&#x20;

<figure><img src="https://3015558743-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFEElAdsRIl9DzfMhbRlB%2Fuploads%2FXoD0YRpHVwT7zQl5gzv2%2Fimage.png?alt=media&#x26;token=f7279922-8964-4d25-89b2-9538516ad8bb" alt=""><figcaption></figcaption></figure>

To add blue whales source, run the query below:&#x20;

```sql
SELECT * FROM carto-demo-data.demo_tables.blue_whales_eastern_pacific_point
```

3. Change the layer name to "Blue Whales". Click over the layer card to start styling the layer.

<figure><img src="https://3015558743-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFEElAdsRIl9DzfMhbRlB%2Fuploads%2F0gUdusCGmppq6oQ1d4Hh%2Fbluewhales_!.gif?alt=media&#x26;token=9c4df248-f7ef-45ee-b903-098c862f9e50" alt=""><figcaption></figcaption></figure>

4. In the *Fill Color* settings, choose a shade of `medium blue`. For the *Stroke Color*, opt for a slightly `lighter blue`.

<figure><img src="https://3015558743-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFEElAdsRIl9DzfMhbRlB%2Fuploads%2FAGTeDpjscylDkgKtijyP%2Fimage.png?alt=media&#x26;token=8f5be6a0-f566-403e-8908-09d01dc79a07" alt=""><figcaption></figcaption></figure>

5. Set the *Stroke Width* to `1` and the *Radius Size* to `1.5`

<figure><img src="https://3015558743-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFEElAdsRIl9DzfMhbRlB%2Fuploads%2FdNb9XGNtewLHiSzCsbAd%2Fimage.png?alt=media&#x26;token=b57f53d7-ab0d-4b3f-8fb1-c5d1084fe92d" alt=""><figcaption></figcaption></figure>

Your map should look something similar to the below:

<figure><img src="https://3015558743-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFEElAdsRIl9DzfMhbRlB%2Fuploads%2F2M0XbARHSj4lnVqbXwhJ%2Fimage.png?alt=media&#x26;token=30fc5a00-35fc-40f6-b3b3-871038b29833" alt=""><figcaption></figcaption></figure>

6. Before we progress to add the Time Series Widget, let's name the map "Blue Whales in Eastern Pacific" and change the *Basemap* to `CARTO Dark Matter`.

<figure><img src="https://3015558743-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFEElAdsRIl9DzfMhbRlB%2Fuploads%2FZ6h2c6o9anW7zlJ3p1t3%2Fimage.png?alt=media&#x26;token=45e0485b-dbfe-4ec9-891d-2b1aba684e3c" alt=""><figcaption></figcaption></figure>

7. Now, let's add a [Time Series Widget](https://academy.carto.com/building-interactive-maps/data-visualization/broken-reference). To do so, open the *Widgets* tab and select *Time Series Widget* type. In the *Data* configuration, add the unique identifier column named `event_id`.

<figure><img src="https://3015558743-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFEElAdsRIl9DzfMhbRlB%2Fuploads%2F0bw95wSUhBDiMko81Kn8%2Fbluewhales_2.gif?alt=media&#x26;token=71043188-5378-49a1-82eb-9f027e67c617" alt=""><figcaption></figcaption></figure>

8. In the *Display* section, set the *Interval* to `1 week` and enable *Animation controls* to allow users animate the features temporarily. Additionally, add a *Note* to provide further context to the end users accessing this map.

<figure><img src="https://3015558743-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFEElAdsRIl9DzfMhbRlB%2Fuploads%2FptbytJy5AFBg5eKA6Bc6%2Fimage.png?alt=media&#x26;token=d105bf13-71f6-4c13-8c95-90813c14d13d" alt=""><figcaption></figcaption></figure>

You can now use the animation controls to animate the map updating its speed, range and so on so you can easily gather whales movement across your desired temporal range.

<figure><img src="https://3015558743-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFEElAdsRIl9DzfMhbRlB%2Fuploads%2FCL6GJAHOOm9hkwgCXFCS%2Fblue_whales_3.gif?alt=media&#x26;token=fb9a3214-a84d-45f1-90da-084ce90bca15" alt=""><figcaption></figcaption></figure>

9. To enhance the storytelling of our animated visualization, we'll give users more background and details. For that, we'll use the [Map Description](https://academy.carto.com/building-interactive-maps/data-visualization/broken-reference) which supports markdown syntax.&#x20;

You can copy the below example or use your own description.

```markdown
### Blue Whales in Eastern Pacific 

![Image: Replace with your own](https://insert-image-url-here.com)

This map animates the migration of blue whales through the Eastern Pacific from 1993 to 2009. 

----
#### How to Use this Map

To discover the migration patterns of blue whales:

- **Explore Timeline**: Hoover over the Time Series graph to obtain insights about the number of seen whales at each aggregated period.
- **See Patterns**: Click 'Play' to animate the whale movements and observe emerging patterns.
- **Filter Data Range**: Drag across a timeline to focus on specific intervals.
- **Navigate**: Pan and zoom to explore different areas of the map.

*Click the top-right button to access the Widget panel*
```

<figure><img src="https://3015558743-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFEElAdsRIl9DzfMhbRlB%2Fuploads%2Fe1thn0aF93QX1fMqUVKT%2Fblue_whales.gif?alt=media&#x26;token=c73a60e1-85c1-4a64-b3df-76881d031075" alt=""><figcaption></figcaption></figure>

10. Now we'll make the map public and share it online with our colleagues. For more details, see [Publishing and sharing maps](https://docs.carto.com/carto-user-manual/maps/publishing-and-sharing-maps).

<figure><img src="https://3015558743-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFEElAdsRIl9DzfMhbRlB%2Fuploads%2FurASCcTFCHpCtfwRcqAX%2Fimage.png?alt=media&#x26;token=32cebe1c-de82-45e7-8b1b-a2d3cb62b12e" alt=""><figcaption></figcaption></figure>

11. The end result should look something similar to the below.

<figure><img src="https://3015558743-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFEElAdsRIl9DzfMhbRlB%2Fuploads%2Fmrg3KOZSnvH8hUFAaG31%2Fimage.png?alt=media&#x26;token=48e8ad20-463b-4e18-ab48-5d9060db0aa1" alt=""><figcaption></figcaption></figure>

### Bonus track

If you're ready to take your map to the next level, dive into our bonus track. Add a layer for individual whale tracks and harness SQL parameters to filter by specific identifiers, enriching your research with targeted insights.

12. Add a new data source to display the whales tracks by executing the following query using Builder SQL Editor:

```sql
SELECT * FROM carto-demo-data.demo_tables.blue_whales_eastern_pacific_line
```

A new layer is added to the map displaying the different blue whales tracks.

<figure><img src="https://3015558743-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFEElAdsRIl9DzfMhbRlB%2Fuploads%2FWwTwZzW75EUtzGCZ3kJT%2Fimage.png?alt=media&#x26;token=34f71973-1142-475d-a39b-9a3d23b83738" alt=""><figcaption></figcaption></figure>

13. Rename the layer to "Whale tracks" and move the layer to the `2nd position`, just below Blue Whales.

<figure><img src="https://3015558743-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFEElAdsRIl9DzfMhbRlB%2Fuploads%2FD1t1rmNXYbPRCHDq5KEh%2Fimage.png?alt=media&#x26;token=2980997a-a401-410d-afcb-5d2ec397bb47" alt=""><figcaption></figcaption></figure>

14. In the layer style configuration of this new layer, set the *Stroke Color* to a `darker blue`.

<figure><img src="https://3015558743-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFEElAdsRIl9DzfMhbRlB%2Fuploads%2F3HNUT8pxKfElr3Xlqdyq%2Fimage.png?alt=media&#x26;token=c9457752-0b55-4174-abb0-fc8c641b3c7f" alt=""><figcaption></figcaption></figure>

Now we will add a Text SQL Parameter to filter both "Blue Whales" and "Whales tracks" by the same identifier.&#x20;

15. We will start adding the parameter and using it on "Whales tracks" layer linked to SQL Query 2. To do so:

* Click on "Add SQL Parameter" and select "Text Parameter" type.
* Use *Add from source* selecting name from SQL Query 2 linked to "Whales tracks" layer.
* Add a *Display name* and *SQL name* to the configuration
* Click on "Create Parameter". Now the parameter control has been added to the map.
* Copy the *SQL nam*e from the parameter control&#x20;
* Add it to your SQL Query 2 adding a WHERE statement and execute your query.

```sql
WHERE name IN {{whale_identifier}}
```

<figure><img src="https://3015558743-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFEElAdsRIl9DzfMhbRlB%2Fuploads%2Fct8LOEme8GEOsagZvggS%2FBlue_Whales_4.gif?alt=media&#x26;token=e6aafbad-6398-4a54-9e99-834c2976c035" alt=""><figcaption></figcaption></figure>

16. Now let's add it to "Blue Whales" data source. To do so, we need to modify the SQL Query 1 to generate the `whales_identifier` by concatenating two string columns as well as adding the WHERE statement using the parameter.

```sql
WITH data_ AS (
  SELECT 
  	*, 
  	CONCAT(individual_local_identifier,'-', tag_local_identifier) as identifier
  FROM carto-demo-data.demo_tables.blue_whales_eastern_pacific_point)
SELECT 
	* 
FROM data_
WHERE identifier IN {{whale_identifier}} 
```

Now if you use the parameter control to filter for a specific identifier, both the "Blue Whales" and the "Whales tracks" are filtered simultaneously.

<figure><img src="https://3015558743-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFEElAdsRIl9DzfMhbRlB%2Fuploads%2FlksslP2y9hNDDDkNty6s%2FBlue_Whales_5.gif?alt=media&#x26;token=56bbb6fd-46db-4855-9836-7d5152c9e39c" alt=""><figcaption></figcaption></figure>

17. Now, let's publish the recent changes and add SQL Parameters to the Map Sharing Settings to allow users explore and filter specific identifiers.

<figure><img src="https://3015558743-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFEElAdsRIl9DzfMhbRlB%2Fuploads%2FnLIOHNRe4zxYLhyCgYrj%2Fblue_whales_6.gif?alt=media&#x26;token=c6b6ab75-a8ef-425b-9e34-ac0d71679425" alt=""><figcaption></figcaption></figure>

The final map from the Bonus Track should look something similar to the below:

{% embed url="<https://clausa.app.carto.com/map/1e9a0387-e08e-4ff7-a7ac-20f46144f0a3>" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://academy.carto.com/building-interactive-maps/data-visualization/build-an-animated-visualization-with-time-series.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
