mirror of
https://github.com/kidwellj/hacking_religion_textbook.git
synced 2024-11-01 01:12:20 +00:00
updated with asides
This commit is contained in:
parent
e02d8fcdf7
commit
b52f19ea58
|
@ -27,3 +27,7 @@ format:
|
||||||
knitr:
|
knitr:
|
||||||
opts_chunk:
|
opts_chunk:
|
||||||
dev: ragg_png
|
dev: ragg_png
|
||||||
|
|
||||||
|
comments:
|
||||||
|
utterances:
|
||||||
|
repo: kidwellj/hacking_religion_textbook
|
|
@ -145,6 +145,8 @@ If you're looking closely, you will notice that I've added two elements to our p
|
||||||
|
|
||||||
If you inspect our chart, you can see that we're getting closer, but it's not really that helpful to compare the totals. What we need to do is get percentages that can be compared side by side. This is easy to do using another `dplyr` feature `mutate`:
|
If you inspect our chart, you can see that we're getting closer, but it's not really that helpful to compare the totals. What we need to do is get percentages that can be compared side by side. This is easy to do using another `dplyr` feature `mutate`:
|
||||||
|
|
||||||
|
[You can find a helpful write-up about dplyr by Antoine Soetewey at, ["Stats and R"](https://statsandr.com/blog/introduction-to-data-manipulation-in-r-with-dplyr/).]{.aside}
|
||||||
|
|
||||||
[It's worth noting that an alternative approach is to leave the numbers intact and simply label them differently so they render as percentages on your charts. You can do this with the `scales() library and the label_percent() function. The downside of this approach is that it won't transfer to tables if you make them.]{.aside}
|
[It's worth noting that an alternative approach is to leave the numbers intact and simply label them differently so they render as percentages on your charts. You can do this with the `scales() library and the label_percent() function. The downside of this approach is that it won't transfer to tables if you make them.]{.aside}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -250,7 +250,6 @@ Content TBD.
|
||||||
:::
|
:::
|
||||||
|
|
||||||
```{r}
|
```{r}
|
||||||
### Spirituality scale --------------------------------------------------------------
|
|
||||||
# Calculate overall mean spirituality score based on six questions:
|
# Calculate overall mean spirituality score based on six questions:
|
||||||
climate_experience_data$spirituality_score <- rowMeans(select(climate_experience_data, Q52a_1:Q52f_1))
|
climate_experience_data$spirituality_score <- rowMeans(select(climate_experience_data, Q52a_1:Q52f_1))
|
||||||
# Calculate overall mean nature relatedness score based on six questions:
|
# Calculate overall mean nature relatedness score based on six questions:
|
||||||
|
@ -261,7 +260,6 @@ climate_experience_data$Q51_score <- rowMeans(select(climate_experience_data, Q5
|
||||||
Like we did in chapter 1, let's start by exploring the data and get a bit of a sense of the character of the responses overall. One good place to start is to find out the mean response for our two continum questions. We can start with religiosity:
|
Like we did in chapter 1, let's start by exploring the data and get a bit of a sense of the character of the responses overall. One good place to start is to find out the mean response for our two continum questions. We can start with religiosity:
|
||||||
|
|
||||||
```{r}
|
```{r}
|
||||||
### Calculating mean --------------------------------------------------------------
|
|
||||||
mean(climate_experience_data$Q57_1)
|
mean(climate_experience_data$Q57_1)
|
||||||
```
|
```
|
||||||
Now let's compare this with the overall mean score for our whole survey pool around spirituality:
|
Now let's compare this with the overall mean score for our whole survey pool around spirituality:
|
||||||
|
@ -277,7 +275,6 @@ This is quite a blunt measure, telling us how the whole average of all the respo
|
||||||
Now let's try out some visualisations, staring with the religiosity data.
|
Now let's try out some visualisations, staring with the religiosity data.
|
||||||
|
|
||||||
```{r}
|
```{r}
|
||||||
### Plotting religiosity --------------------------------------------------------------
|
|
||||||
ggplot(climate_experience_data, aes(x = 1, y = Q57_1)) +
|
ggplot(climate_experience_data, aes(x = 1, y = Q57_1)) +
|
||||||
geom_point() +
|
geom_point() +
|
||||||
labs(x = NULL, y = "Q57_1")
|
labs(x = NULL, y = "Q57_1")
|
||||||
|
@ -292,11 +289,13 @@ ggplot(climate_experience_data, aes(x = 1, y = Q57_1)) +
|
||||||
|
|
||||||
You'll also notice that we've hidden the x-axis value labels as these are just random numbers and not really something we want to draw attention to. We've also hidden the label for that axis.
|
You'll also notice that we've hidden the x-axis value labels as these are just random numbers and not really something we want to draw attention to. We've also hidden the label for that axis.
|
||||||
|
|
||||||
|
This is visually pretty chaotic, but you can see probably see some places where the dots are thicker and get the sense that there are more in the top than the bottom.
|
||||||
|
|
||||||
Since this is quite a large plot, I'd recommend going one step further and making the dots a bit smaller, and a bit transparent (this is called "alpha" in R). The advantage of this is that we'll be able to tell visually when dots are overlapping and register that there is a cluster. When they're all the same black color, this is impossible to tell.
|
Since this is quite a large plot, I'd recommend going one step further and making the dots a bit smaller, and a bit transparent (this is called "alpha" in R). The advantage of this is that we'll be able to tell visually when dots are overlapping and register that there is a cluster. When they're all the same black color, this is impossible to tell.
|
||||||
|
|
||||||
```{r}
|
```{r}
|
||||||
ggplot(climate_experience_data, aes(x = 1, y = Q57_1)) +
|
ggplot(climate_experience_data, aes(x = 1, y = Q57_1)) +
|
||||||
geom_point(position = position_jitter(width = 1), color="black", size=0.5, alpha=0.3) +
|
geom_point(position = position_jitter(width = 1), color="black", size=1.5, alpha=0.3) +
|
||||||
labs(x = NULL, y = "Q57_1") + theme(axis.text.x = element_blank())
|
labs(x = NULL, y = "Q57_1") + theme(axis.text.x = element_blank())
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -387,6 +386,8 @@ ggplot(climate_experience_data, aes(x = spirituality_score, y = Q57_1)) +
|
||||||
|
|
||||||
It may be helpful to add a few more visual elements to help someone understand this data. Let's try adding a density plot:
|
It may be helpful to add a few more visual elements to help someone understand this data. Let's try adding a density plot:
|
||||||
|
|
||||||
|
[If you'd like to explore a wider range of correlation plots, you might want to check out Data Analysis and Visualization in R Using smplot2, ["data import"](https://smin95.github.io/dataviz/basics-of-ggplot2-and-correlation-plot.html).]{.aside}
|
||||||
|
|
||||||
```{r}
|
```{r}
|
||||||
library(ggExtra)
|
library(ggExtra)
|
||||||
p <- ggplot(climate_experience_data, aes(x = spirituality_score, y = Q57_1)) +
|
p <- ggplot(climate_experience_data, aes(x = spirituality_score, y = Q57_1)) +
|
||||||
|
|
Loading…
Reference in a new issue