You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
__The goal of this tutorial is to advance skills in data synthesis, particularly visualisation, manipulation, efficiently handling datasets and customising figures to make them both beautiful and informative. Here, we will focus on using packages from the `tidyverse` collection and a few extras, which together can streamline data visualisation and make your research pop out more!__
24
+
__The goal of this tutorial is to advance skills in visualisation, manipulation, efficiently handling datasets and customising figures to make them both beautiful and informative. Here, we will focus on using packages from the `tidyverse` collection and a few extras, which together can streamline data visualisation and make your research pop out more!__
25
25
26
26
</div>
27
27
28
+
### Before we get to the code, here are some of the things that are important to consider when making graphs and telling a scientific story.
## All the files you need to complete this tutorial can be downloaded from <ahref="https://github.com/ourcodingclub/CC-dataviz-beautification-synthesis"target="_blank">this repository</a>. __Click on `Code/Download ZIP` and unzip the folder, or clone the repository to your own GitHub account.__
29
33
30
34
`R` really shines when it comes to data visualisation and with some tweaks, you can make eye-catching plots that make it easier for people to understand your science. The `ggplot2` package, part of the `tidyverse` collection of packages, as well as its many extension packages are a great tool for data visualisation, and that is the world that we will jump into over the course of this tutorial.
### Congrats on taking three different types of figures on beautification journeys and all the best with the rest of your data syntheses!
1140
+
The world of coding and packages is pretty dynamic and things change - like how since I originally made the graphs above, the `theme_clean()` function changed and now makes a slightly different type of graph. Perhaps you notice horizontal lines going across the plot. Sometimes they can be useful, other times less so as they can distract people and make the graph look less clean (ironic given the theme name). So for our next step, we will make our own theme.
1141
+
1142
+
```r
1143
+
# Make a new theme
1144
+
theme_coding<-function(){ # creating a new theme function
1145
+
theme_bw()+# using a predefined theme as a base
1146
+
theme(axis.text.x= element_text(size=12, vjust=1, hjust=1), # customising lots of things
### A data storytelling tip: Find something to highlight, is there a story amidst all the points?
1159
+
1160
+
While having lots of data is often impressive, it can also make it hard to actually figure out what the key message of the graph is. In this tutorial we are exploring how bird populations are changing over time. Might be cool to highlight a particular species, like this mallee emu-wren, a small bird that hasn't experienced particularly dramatic population changes. But in a time of global change, telling apart relatively stable populations is also important!
<center>Illustration by <ahref="https://www.malkolmboothroyd.com"target="_blank">Malkolm Boothroyd</a></center>
1164
+
1165
+
We could make the mallee emu-wren point bigger and a different colour, for which we essentially need a column that says whether or not a given record is for the mallee emu-wren.
1166
+
1167
+
### A data manipulation tip: Using case_when(), combined with mutate, is a great way to create new variables based on one or more conditions from other variables.
1168
+
1169
+
```r
1170
+
# Create new columns based on a combo of conditions using case_when()
Now we are ready for an even snazzier graph! One thing you might notice is different is that before we added our data frame right at the start in the first line inside the `ggplot()`, whereas now we are adding the data inside each specific element - `geom_point`, `geom_smooth`, etc. This way `ggplot` gets less confused about what elements of the code apply to which parts of the graph - a useful thing to do when making more complex graphs.
1177
+
1178
+
We can also add our mallee emu-wren illustration to the plot!
You can save it using `ggsave()` - you could use either `png` or `pdf` depending on your needs - `png` files are raster files and if you keep zooming, they will become blurry and are not great for publications or printed items. `pdf` files are vectorised so you can keep zooming to your delight and they look better in print but are larger files, not as easy to embed online or in presentations. So think of where your story is going and that can help you decide of the file format.
We have highlighted the mallee emu-wren - a great thing to do if we are say a scientist working on this species, or a conservation organisation focusing on its protection, or we just really like this cute little Australian bird. When trying to tell a story with data though, it's always nice to put things in perspective and maps are a very handy way of doing that. We could tell the story of bird monitoring around the world, highlight a region of interest (Australia) and then give the story an anchor - the mallee emu-wren!
1233
+
1234
+
First, we will create the map - here is how to make an object with the world in it.
1235
+
1236
+
```r
1237
+
world<- map_data("world")
1238
+
```
1239
+
1240
+
Next up, we can extract the coordinates of the different bird populations monitored around the world.
1241
+
1242
+
```r
1243
+
bird_coords<-bird_pops_long %>%
1244
+
dplyr::select(3:27) %>%
1245
+
distinct()
1246
+
```
1247
+
1248
+
And now we are ready for our map! One way to learn what each line does is to have a go at commenting it out using a `#` and then spotting what changes - or you can check out the comments below each line.
0 commit comments