Blog Home!

Tutorial: How to Use the “timeuse” Package and Make Visualizations
Project: Time Use Visualizations
Step 1. Download ATUS-X extract
Create your ATUS-X extract from IPUMS website. Make sure to include 'DURATION', 'CASEID', 'ACTIVITY', 'ACTLINE' and weights variables ('WT06') if needed. Save .dta and .xml file, preferably in a new created 'data' folder. Load extract into R using 'ipumsr' package.Step 2. Download or create your own activity codes file
Create an activities code file, or you can download mine. It has to be a .csv file with 3 columns (ACTIVITY, Name, Alphabet).- ACTIVITY is the activity code from ATUS-X, ranges from 10101 to 509999,
- Name is the name you want to give to this activity code, e.g. 'Sleep,' 'Leisure,' etc.,
- Alphabet is an alphabet letter (a to z) to code the activities.
Step 3. Transform your data
Using the 'timeuse' package (Link), contains five functions that will help you with that:
- tu_tempogram()
- tu_transitions()
- tu_totals()
- tu_maps()
- tu_path()
Step 4. Create the visualizations
Using one of the following packages:- tempogram
- transitions
- totals
- usmap
- path
Step 5. Save your visualization as .html file
In the viewer of your RStudio, choose 'Save as Web Page..." and save your file as 'myfile.html'.
Step 6. Upload your html file to your GitHub page or website
If you have a GitHub.io page, upload it to your main folder, and your file will be viewable at <yourGitName>.github.io/<yourfilename>Step 7. Use <iframes> to add your visualization to your blog
For example, in WordPress you can do the following to add your graph to your blog:
Examples
These lines will create your tempogram from 'data' (data = ATUS-X extract).tem <- tu_tempogram(data, w = "WT06") tempogram(toJSON(tem)) #don't forget to use toJSON from 'jsonlite' package)If you need to change width or height of the visualization, use these:
tempogram(toJSON(tem), width="auto", height = "550px")