mirror of
https://github.com/kidwellj/hacking_religion_textbook.git
synced 2024-11-01 09:22:21 +00:00
513 lines
28 KiB
R
513 lines
28 KiB
R
|
q6_data_plot
|
||
|
ggsave("figures/q6.png", width = 15, height = 10, units = "cm")
|
||
|
# Faceted plot working with 3x3 grid
|
||
|
df <- select(climate_experience_data, Q52_bin, Q53_bin, Q57_bin, Q6)
|
||
|
names(df) <- c("Q52_bin", "Q53_bin", "Q57_bin", "response")
|
||
|
facet_names <- c(`Q52_bin` = "Spirituality", `Q53_bin` = "Politics L/R", `Q57_bin` = "Religiosity", `low`="low", `medium`="medium", `high`="high")
|
||
|
facet_labeller <- function(variable,value){return(facet_names[value])}
|
||
|
q6_levels = c("Definitely changing", "Probably changing", "Probably not changing", "Definitely not changing")
|
||
|
df$response <- factor(df$response, ordered = TRUE, levels = c("4", "3", "2", "1"))
|
||
|
df$response <- fct_recode(df$response, "Definitely not changing" = "1", "Probably not changing" = "2", "Probably changing" = "3", "Definitely changing" = "4")
|
||
|
# TODO: not working with function, need to sort out why
|
||
|
df %>%
|
||
|
# we need to get the data including facet info in long format, so we use pivot_longer()
|
||
|
pivot_longer(!response, names_to = "bin_name", values_to = "b") %>%
|
||
|
# add counts for plot below
|
||
|
count(response, bin_name, b) %>%
|
||
|
group_by(bin_name,b) %>%
|
||
|
mutate(perc=paste0(round(n*100/sum(n),1),"%")) %>%
|
||
|
# run ggplot
|
||
|
ggplot(aes(x = n, y = "", fill = response)) +
|
||
|
geom_col(position=position_fill(), aes(fill=response)) +
|
||
|
geom_text(aes(label = perc), position = position_fill(vjust=.5), size=2) +
|
||
|
scale_fill_brewer(palette="YlOrBr") +
|
||
|
scale_x_continuous(labels = scales::percent_format()) +
|
||
|
facet_grid(vars(b), vars(bin_name), labeller=as_labeller(facet_names)) +
|
||
|
labs(caption = caption, x = "", y = "") +
|
||
|
guides(fill = guide_legend(title = NULL))
|
||
|
ggsave("figures/q6_faceted.png", width = 20, height = 10, units = "cm")
|
||
|
library(readr)
|
||
|
library(stringr)
|
||
|
library(dplyr)
|
||
|
library(ggplot2)
|
||
|
hesa_students <- read_delim("~/Nextcloud/academic_service/TRS-UK/whiteness_research/hesa_data/hesa_all_ethnicity_utf8.csv",
|
||
|
"\t", escape_double = FALSE, col_names = c("ay","ethnicity","sub_subject","subject","level","provider","fpe_pct", "fpe"),
|
||
|
col_types = cols(ay = col_number(), fpe_pct = col_number(), fpe = col_number()), trim_ws = TRUE, skip = 1)
|
||
|
# Convert NA to 0 for the sake of plot below
|
||
|
# hesa_students$fpe[is.na(hesa_students$fpe)] <- 0
|
||
|
# Omit rows with NA
|
||
|
hesa_students_filtered <- hesa_students %>% filter(!is.na(fpe))
|
||
|
# Calculate totals for sector
|
||
|
arrange(hesa_students_v6, provider, level, ay, ethnicity)
|
||
|
# Calculate totals for sector
|
||
|
arrange(hesa_students_filtered, provider, level, ay, ethnicity)
|
||
|
hesa_students_v6_grouped <- group_by(hesa_students_v6, level, ay, ethnicity)
|
||
|
hesa_students_v6_grouped <- group_by(hesa_students_filtered, level, ay, ethnicity)
|
||
|
# Calculate sum of all students by ethnicity across all provider departments
|
||
|
hesa_students_v6_grouped_totals <- summarise(hesa_students_v6_grouped, fpe = sum(fpe))
|
||
|
ggplot(data = hesa_students_v6_grouped_totals, aes(x=ay, y=fpe, colour=ethnicity)) + geom_point() + facet_grid( ~ level) + geom_smooth(method= "lm", se=FALSE)
|
||
|
View(hesa_students_v6_grouped)
|
||
|
View(hesa_students_filtered)
|
||
|
# R Setup -----------------------------------------------------------------
|
||
|
library(here) # much better way to manage working paths in R across multiple instances
|
||
|
library(ragg) # better video device, more accurate and faster rendering, esp. on macos. Also should enable system fonts for display
|
||
|
library(tidyverse)
|
||
|
library(tidytext) # used for reorder_within() for factor and likert plots
|
||
|
require(devtools)
|
||
|
require(usethis)
|
||
|
require(likert) # Used for likert data visualisation
|
||
|
require(RColorBrewer)
|
||
|
require(scales) # Used for adding percentages to bar charts
|
||
|
library(ggthemes)
|
||
|
library(hrbrthemes) # Used for ipsum theme etc.
|
||
|
library(ggeasy) # Used for centring titles
|
||
|
library(reshape2) # Added for use with centred stacked bar charts
|
||
|
library(viridis) # Used for gradient colour schemes, as with violin plots
|
||
|
library("readxl")
|
||
|
library("htmlwidgets")
|
||
|
library("ggstatsplot")
|
||
|
library(showtext)
|
||
|
library(glue) # used for clean_postcodes
|
||
|
library(magrittr) # used for clean_postcodes
|
||
|
require(RCurl) # used for fetching reproducible datasets
|
||
|
require(sf) # new simplefeature data class, supercedes sp in many ways
|
||
|
require(tmap)
|
||
|
library(sp) # used to define CRS below only
|
||
|
library(flextable) # pretty tables
|
||
|
library(officer)
|
||
|
library(ggrepel)
|
||
|
library(patchwork) # used for side-by-side plotting (q19 etc.)
|
||
|
library(gridExtra)
|
||
|
library('foreign')
|
||
|
library(regions)
|
||
|
library(countrycode)
|
||
|
library(haven) # used for importing SPSS .sav files
|
||
|
caption <- "Jeremy H. Kidwell and Charles Ogunbode,\nGraphic is CC-by-SA 4.0"
|
||
|
title <- "To what extent do you support or oppose the following policies?"
|
||
|
q34_data <- select(climate_experience_data, Q34_ev:Q34_loss_and_damage)
|
||
|
names(q34_data) <- c("Subsidies for electric (emission-free) vehicles", "Improving public transport", "Increasing taxes on any use of fossil fuels", "Increasing the price of electricity to reduce our consumption", "Increasing taxes on carbon-intensive foods like meat and dairy products", "Additional charges for people who fly more than twice a year", "Increasing taxes on companies and industries that emit large amounts of carbon", "Using public money to subsidise renewable energy (such as wind and solar power", "Including nuclear power in the energy mix", "Spending public money now to prepare the UK for the impacts of climate change", "Spending public money to help people in developing countries adapt to harmful climate change impacts", "Using public money to compensate developing countries for loss and damage")
|
||
|
q34_levels <- c("strongly oppose", "tend to oppose", "tend to support", "strongly support")
|
||
|
q34_likert_table <- q34_data %>%
|
||
|
mutate(across(everything(),
|
||
|
factor, ordered = TRUE, levels = 1:4, labels=q34_levels)) %>%
|
||
|
as.data.frame %>%
|
||
|
likert
|
||
|
plot(q34_likert_table, wrap=45, text.size=3, ordered=TRUE, low.color='#B18839', high.color='#590048') +
|
||
|
labs(title = title, caption = NULL, y="") +
|
||
|
guides(fill = guide_legend(title = NULL)) +
|
||
|
theme_ipsum() +
|
||
|
theme(plot.title = element_text(lineheight = 0.9, size =12, hjust = 0)) +
|
||
|
scale_y_continuous(labels = abs, limits = c(-115, 115))
|
||
|
# save to png file for reports
|
||
|
ggsave("figures/q34_likert.png", width = 20, height = 20, units = "cm")
|
||
|
# Q48
|
||
|
title <- "To what extent do you agree or disagree \nwith the following statements"
|
||
|
caption <- "Jeremy H. Kidwell and Charles Ogunbode,\nGraphic is CC-by-SA 4.0"
|
||
|
q48_data <- select(climate_experience_data, Q48_poor_suffer:Q48_colonialism)
|
||
|
names(q48_data) <- c("People living in poverty suffer worse effects from climate change", "Around the world, people who are least responsible suffer the worst negative impacts from climate change", "Climate change affects women around the world worse than men", "Climate change will increase existing inequalities", "The effects of climate change are worse for people of colour", "Solving climate change requires redistribution of resources from the wealthy to those who have less", "People from communities most affected by climate change should have more of a say in decisions about solutions to climate change than they currently do", "Climate change is driven and exacerbated by exploitative systems like colonialism and capitalism")
|
||
|
q48_levels <- c("Strongly disagree", "Somewhat disagree", "Neither agree nor disagree", "Somewhat agree", "Strongly agree")
|
||
|
q48_likert_table <- q48_data %>%
|
||
|
mutate(across(everything(),
|
||
|
factor, ordered = TRUE, levels = 1:5, labels=q48_levels)) %>%
|
||
|
as.data.frame %>%
|
||
|
likert
|
||
|
plot(q48_likert_table, wrap=40, text.size=3, ordered=TRUE, low.color='#B18839', high.color='#590048') +
|
||
|
labs(title = title, caption = NULL, y="") +
|
||
|
guides(fill = guide_legend(title = NULL)) +
|
||
|
theme_ipsum() +
|
||
|
theme(axis.text.y = element_text(size = 9)) +
|
||
|
scale_y_continuous(labels = abs, limits = c(-110, 110))
|
||
|
# save to png file for reports
|
||
|
ggsave("figures/q48_likert.png", width = 20, height = 18, units = "cm")
|
||
|
plot(q48_likert_table, wrap=40, text.size=3, ordered=TRUE, low.color='#B18839', high.color='#590048') +
|
||
|
labs(title = title, caption = NULL, y="") +
|
||
|
guides(fill = guide_legend(title = NULL)) +
|
||
|
theme_ipsum() +
|
||
|
theme(axis.text.y = element_text(size = 9)) +
|
||
|
scale_y_continuous(labels = abs, limits = c(-105, 105))
|
||
|
# save to png file for reports
|
||
|
ggsave("figures/q48_likert.png", width = 20, height = 18, units = "cm")
|
||
|
plot(q48_likert_table, wrap=40, text.size=3, ordered=TRUE, low.color='#B18839', high.color='#590048') +
|
||
|
labs(title = title, caption = NULL, y="") +
|
||
|
guides(fill = guide_legend(title = NULL)) +
|
||
|
theme_ipsum() +
|
||
|
theme(axis.text.y = element_text(size = 9)) +
|
||
|
scale_y_continuous(labels = abs, limits = c(-115, 115))
|
||
|
# save to png file for reports
|
||
|
ggsave("figures/q48_likert.png", width = 20, height = 18, units = "cm")
|
||
|
# Q42
|
||
|
title <- "To what degree would you say each of the following stops \nyou or acts as a barrier to you taking more \naction on climate change?"
|
||
|
caption <- "Jeremy H. Kidwell and Charles Ogunbode,\nGraphic is CC-by-SA 4.0"
|
||
|
q42_data <- select(climate_experience_data, Q42_lacking_knowledge:Q42_other)
|
||
|
names(q42_data) <- c("Feeling that you have insufficient awareness or knowledge of climate change", "Feeling uncertain or skeptical about climate change", "Lacking trust in information sources", "Difficulty or inconvenience of climate actions or climate-friendly lifestyle changes", "Feeling that individual action to address climate change is ineffective", "Feeling is too late to slow or reverse the negative effects of climate change", "Other things taking up your time and energy", "Other barriers not included in this list")
|
||
|
q42_levels <- c("Not at all", "A little", "A great deal")
|
||
|
q42_likert_table <- q42_data %>%
|
||
|
mutate(across(everything(),
|
||
|
factor, ordered = TRUE, levels = 1:3, labels=q42_levels)) %>%
|
||
|
as.data.frame %>%
|
||
|
likert
|
||
|
plot(q42_likert_table, wrap=45, centered=FALSE, text.size=3, ordered=TRUE, low.color='#B18839', high.color='#590048') +
|
||
|
labs(title = title, y="") +
|
||
|
guides(fill = guide_legend(title = NULL)) +
|
||
|
theme_ipsum() +
|
||
|
theme(plot.title = element_text(lineheight = 0.9, size =12, hjust = 0)) +
|
||
|
scale_y_continuous(labels = abs, limits = c(-5, 110))
|
||
|
# save to png file for reports
|
||
|
ggsave("figures/q42_likert.png", width = 20, height = 15, units = "cm")
|
||
|
plot(q42_likert_table, wrap=45, centered=TRUE, text.size=3, ordered=TRUE, low.color='#B18839', high.color='#590048') +
|
||
|
labs(title = title, y="") +
|
||
|
guides(fill = guide_legend(title = NULL)) +
|
||
|
theme_ipsum() +
|
||
|
theme(plot.title = element_text(lineheight = 0.9, size =12, hjust = 0)) +
|
||
|
scale_y_continuous(labels = abs, limits = c(-5, 110))
|
||
|
# save to png file for reports
|
||
|
ggsave("figures/q42_likert.png", width = 20, height = 15, units = "cm")
|
||
|
plot(q42_likert_table, wrap=45, centered=FALSE, text.size=3, ordered=TRUE, low.color='#B18839', high.color='#590048') +
|
||
|
labs(title = title, y="") +
|
||
|
guides((title = NULL)) +
|
||
|
theme_ipsum() +
|
||
|
theme(plot.title = element_text(lineheight = 0.9, size =12, hjust = 0)) +
|
||
|
scale_y_continuous(labels = abs, limits = c(-5, 110))
|
||
|
# save to png file for reports
|
||
|
ggsave("figures/q42_likert.png", width = 20, height = 15, units = "cm")
|
||
|
plot(q42_likert_table, wrap=45, text.size=3, ordered=TRUE, low.color='#B18839', high.color='#590048') +
|
||
|
labs(title = title, y="") +
|
||
|
guides(fill = guide_legend(title = NULL)) +
|
||
|
theme_ipsum() +
|
||
|
theme(plot.title = element_text(lineheight = 0.9, size =12, hjust = 0)) +
|
||
|
scale_y_continuous(labels = abs, limits = c(-110, 110))
|
||
|
# save to png file for reports
|
||
|
ggsave("figures/q42_likert.png", width = 20, height = 15, units = "cm")
|
||
|
plot(q42_likert_table, center=1, wrap=45, text.size=3, ordered=TRUE, low.color='#B18839', high.color='#590048') +
|
||
|
labs(title = title, y="") +
|
||
|
guides(fill = guide_legend(title = NULL)) +
|
||
|
theme_ipsum() +
|
||
|
theme(plot.title = element_text(lineheight = 0.9, size =12, hjust = 0)) +
|
||
|
scale_y_continuous(labels = abs, limits = c(-110, 110))
|
||
|
# save to png file for reports
|
||
|
ggsave("figures/q42_likert.png", width = 20, height = 15, units = "cm")
|
||
|
plot(q42_likert_table, center=2, wrap=45, text.size=3, ordered=TRUE, low.color='#B18839', high.color='#590048') +
|
||
|
labs(title = title, y="") +
|
||
|
guides(fill = guide_legend(title = NULL)) +
|
||
|
theme_ipsum() +
|
||
|
theme(plot.title = element_text(lineheight = 0.9, size =12, hjust = 0)) +
|
||
|
scale_y_continuous(labels = abs, limits = c(-110, 110))
|
||
|
# save to png file for reports
|
||
|
ggsave("figures/q42_likert.png", width = 20, height = 15, units = "cm")
|
||
|
plot(q42_likert_table, center=3, wrap=45, text.size=3, ordered=TRUE, low.color='#B18839', high.color='#590048') +
|
||
|
labs(title = title, y="") +
|
||
|
guides(fill = guide_legend(title = NULL)) +
|
||
|
theme_ipsum() +
|
||
|
theme(plot.title = element_text(lineheight = 0.9, size =12, hjust = 0)) +
|
||
|
scale_y_continuous(labels = abs, limits = c(-110, 110))
|
||
|
# save to png file for reports
|
||
|
ggsave("figures/q42_likert.png", width = 20, height = 15, units = "cm")
|
||
|
plot(q42_likert_table, center=3, centered=true, wrap=45, text.size=3, ordered=TRUE, low.color='#B18839', high.color='#590048') +
|
||
|
labs(title = title, y="") +
|
||
|
guides(fill = guide_legend(title = NULL)) +
|
||
|
theme_ipsum() +
|
||
|
theme(plot.title = element_text(lineheight = 0.9, size =12, hjust = 0)) +
|
||
|
scale_y_continuous(labels = abs, limits = c(-110, 110))
|
||
|
# save to png file for reports
|
||
|
ggsave("figures/q42_likert.png", width = 20, height = 15, units = "cm")
|
||
|
plot(q42_likert_table, center=3, centered=TRUE, wrap=45, text.size=3, ordered=TRUE, low.color='#B18839', high.color='#590048') +
|
||
|
labs(title = title, y="") +
|
||
|
guides(fill = guide_legend(title = NULL)) +
|
||
|
theme_ipsum() +
|
||
|
theme(plot.title = element_text(lineheight = 0.9, size =12, hjust = 0)) +
|
||
|
scale_y_continuous(labels = abs, limits = c(-110, 110))
|
||
|
plot(q42_likert_table, center=1.5, centered=TRUE, wrap=45, text.size=3, ordered=TRUE, low.color='#B18839', high.color='#590048') +
|
||
|
labs(title = title, y="") +
|
||
|
guides(fill = guide_legend(title = NULL)) +
|
||
|
theme_ipsum() +
|
||
|
theme(plot.title = element_text(lineheight = 0.9, size =12, hjust = 0)) +
|
||
|
scale_y_continuous(labels = abs, limits = c(-110, 110))
|
||
|
# save to png file for reports
|
||
|
ggsave("figures/q42_likert.png", width = 20, height = 15, units = "cm")
|
||
|
plot(q42_likert_table, center=1.5, centered=TRUE, wrap=45, text.size=3, ordered=TRUE, low.color='#B18839', high.color='#590048') +
|
||
|
labs(title = title, y="") +
|
||
|
guides(fill = guide_legend(title = NULL)) +
|
||
|
theme_ipsum() +
|
||
|
theme(plot.title = element_text(lineheight = 0.9, size =12, hjust = 0)) +
|
||
|
scale_y_continuous(labels = abs, limits = c(-110, 105))
|
||
|
# save to png file for reports
|
||
|
ggsave("figures/q42_likert.png", width = 20, height = 15, units = "cm")
|
||
|
plot(q42_likert_table, center=1.5, centered=TRUE, wrap=45, text.size=3, ordered=TRUE, low.color='#B18839', high.color='#590048') +
|
||
|
labs(title = title, y="") +
|
||
|
guides(fill = guide_legend(title = NULL)) +
|
||
|
theme_ipsum() +
|
||
|
theme(plot.title = element_text(lineheight = 0.9, size =12, hjust = 0)) +
|
||
|
scale_y_continuous(labels = abs, limits = c(-110, 115))
|
||
|
# save to png file for reports
|
||
|
ggsave("figures/q42_likert.png", width = 20, height = 15, units = "cm")
|
||
|
# Q25 - generate diverging stacked bar chart using likert()
|
||
|
title <- "How serious a threat do you think \nclimate change poses to the following?"
|
||
|
caption <- "Jeremy H. Kidwell and Charles Ogunbode,\nGraphic is CC-by-SA 4.0"
|
||
|
q25_data <- select(climate_experience_data, Q25_self_and_family:Q25_outside_uk)
|
||
|
names(q25_data) <- c("You and your family in the UK", "People in your local area or city", "The UK as a whole", "Your family and/or friends living outside the UK")
|
||
|
# Set up levels text for question responses
|
||
|
q25_levels <- paste(c("not at all", "somewhat", "moderately", "very", "extremely"),
|
||
|
"serious")
|
||
|
q25_likert_table <- q25_data %>%
|
||
|
mutate(across(everything(),
|
||
|
factor, ordered = TRUE, levels = 1:5, labels=q25_levels)) %>%
|
||
|
as.data.frame %>%
|
||
|
likert
|
||
|
plot(q25_likert_table, centered=FALSE, wrap=20, text.size=3, ordered=TRUE, low.color='#B18839', high.color='#590048') +
|
||
|
ggtitle(title) +
|
||
|
labs(title = title, caption = NULL, y="") +
|
||
|
guides(fill = guide_legend(title = NULL)) +
|
||
|
theme_ipsum_rc() +
|
||
|
theme(axis.text.y = element_text(size = 9))
|
||
|
# save to png file for reports
|
||
|
ggsave("figures/q25_likert.png", width = 20, height = 10, units = "cm")
|
||
|
# using ggplot
|
||
|
worry_elsewhere_data <- qualtrics_process_single_multiple_choice_unsorted(climate_experience_data_named$Q28)
|
||
|
# add percentages for plot
|
||
|
worry_elsewhere_data <- worry_elsewhere_data %>%
|
||
|
dplyr::mutate(perc = scales::percent(n / sum(n), accuracy = 1, trim = FALSE))
|
||
|
worry_elsewhere_ggpie <- ggplot(worry_elsewhere_data, aes(x = "", y = n, fill = response)) +
|
||
|
geom_col() +
|
||
|
geom_text(aes(label = perc),
|
||
|
color = "white",
|
||
|
position = position_stack(vjust = 0.5),
|
||
|
show.legend = FALSE) +
|
||
|
coord_polar(theta = "y") +
|
||
|
# colours for slices
|
||
|
scale_fill_manual(values = c("#3962B1", "#B1399E")) +
|
||
|
# remove labels and add caption
|
||
|
labs(title = title, x = "", y = "") +
|
||
|
# remove extra lines
|
||
|
theme(axis.text = element_blank(),
|
||
|
axis.ticks = element_blank(),
|
||
|
axis.title = element_blank(),
|
||
|
panel.grid = element_blank(),
|
||
|
plot.background = element_rect(fill = white),
|
||
|
panel.background = element_rect(fill = white)) +
|
||
|
# remove legend title
|
||
|
guides(fill = guide_legend(title = NULL))
|
||
|
worry_elsewhere_ggpie
|
||
|
ggsave("figures/figure6.png", width = 20, height = 10, units = "cm")
|
||
|
caption <- "Jeremy H. Kidwell and Charles Ogunbode,\nGraphic is CC-by-SA 4.0"
|
||
|
title <- "To what extent do you support or oppose the following policies?"
|
||
|
q34_data <- select(climate_experience_data, Q34_ev:Q34_loss_and_damage)
|
||
|
names(q34_data) <- c("Subsidies for electric (emission-free) vehicles", "Improving public transport", "Increasing taxes on any use of fossil fuels", "Increasing the price of electricity to reduce our consumption", "Increasing taxes on carbon-intensive foods like meat and dairy products", "Additional charges for people who fly more than twice a year", "Increasing taxes on companies and industries that emit large amounts of carbon", "Using public money to subsidise renewable energy (such as wind and solar power", "Including nuclear power in the energy mix", "Spending public money now to prepare the UK for the impacts of climate change", "Spending public money to help people in developing countries adapt to harmful climate change impacts", "Using public money to compensate developing countries for loss and damage")
|
||
|
q34_levels <- c("strongly oppose", "tend to oppose", "tend to support", "strongly support")
|
||
|
q34_likert_table <- q34_data %>%
|
||
|
mutate(across(everything(),
|
||
|
factor, ordered = TRUE, levels = 1:4, labels=q34_levels)) %>%
|
||
|
as.data.frame %>%
|
||
|
likert
|
||
|
plot(q34_likert_table, wrap=45, text.size=3, ordered=TRUE, low.color='#B18839', high.color='#590048') +
|
||
|
labs(title = title, caption = NULL, y="") +
|
||
|
guides(fill = guide_legend(title = NULL)) +
|
||
|
theme_ipsum() +
|
||
|
theme(plot.title = element_text(lineheight = 0.9, size =12, hjust = 0)) +
|
||
|
scale_y_continuous(labels = abs, limits = c(-115, 115))
|
||
|
# save to png file for reports
|
||
|
ggsave("figures/figure7.png", width = 20, height = 20, units = "cm")
|
||
|
title <- "Have you ever heard of the phrase “Climate Justice”?"
|
||
|
caption <- "Jeremy H. Kidwell and Charles Ogunbode,\nGraphic is CC-by-SA 4.0"
|
||
|
q45_data <- qualtrics_process_single_multiple_choice(climate_experience_data_named$Q45)
|
||
|
q45_plot <- plot_horizontal_bar(q45_data) + labs(title = title, caption = NULL, x = "", y = "")
|
||
|
q45_plot
|
||
|
ggsave("figures/figure8.png", width = 20, height = 5, units = "cm")
|
||
|
# Q48
|
||
|
title <- "To what extent do you agree or disagree \nwith the following statements"
|
||
|
caption <- "Jeremy H. Kidwell and Charles Ogunbode,\nGraphic is CC-by-SA 4.0"
|
||
|
q48_data <- select(climate_experience_data, Q48_poor_suffer:Q48_colonialism)
|
||
|
names(q48_data) <- c("People living in poverty suffer worse effects from climate change", "Around the world, people who are least responsible suffer the worst negative impacts from climate change", "Climate change affects women around the world worse than men", "Climate change will increase existing inequalities", "The effects of climate change are worse for people of colour", "Solving climate change requires redistribution of resources from the wealthy to those who have less", "People from communities most affected by climate change should have more of a say in decisions about solutions to climate change than they currently do", "Climate change is driven and exacerbated by exploitative systems like colonialism and capitalism")
|
||
|
q48_levels <- c("Strongly disagree", "Somewhat disagree", "Neither agree nor disagree", "Somewhat agree", "Strongly agree")
|
||
|
q48_likert_table <- q48_data %>%
|
||
|
mutate(across(everything(),
|
||
|
factor, ordered = TRUE, levels = 1:5, labels=q48_levels)) %>%
|
||
|
as.data.frame %>%
|
||
|
likert
|
||
|
plot(q48_likert_table, wrap=40, text.size=3, ordered=TRUE, low.color='#B18839', high.color='#590048') +
|
||
|
labs(title = title, caption = NULL, y="") +
|
||
|
guides(fill = guide_legend(title = NULL)) +
|
||
|
theme_ipsum() +
|
||
|
theme(axis.text.y = element_text(size = 9)) +
|
||
|
scale_y_continuous(labels = abs, limits = c(-1105, 115))
|
||
|
# save to png file for reports
|
||
|
ggsave("figures/figure9.png", width = 20, height = 18, units = "cm")
|
||
|
plot(q48_likert_table, wrap=40, text.size=3, ordered=TRUE, low.color='#B18839', high.color='#590048') +
|
||
|
labs(title = title, caption = NULL, y="") +
|
||
|
guides(fill = guide_legend(title = NULL)) +
|
||
|
theme_ipsum() +
|
||
|
theme(axis.text.y = element_text(size = 9)) +
|
||
|
scale_y_continuous(labels = abs, limits = c(-105, 115))
|
||
|
# save to png file for reports
|
||
|
ggsave("figures/figure9.png", width = 20, height = 18, units = "cm")
|
||
|
# Q40
|
||
|
title <- "Have you engaged in the following \nactivities in the past year?"
|
||
|
q40_data <- select(climate_experience_data, Q39_protest:Q39_active_member)
|
||
|
names(q40_data) <- c("Attended a climate protest", "Donated money to an environmental organisation tackling climate change", "Changed your lifestyle to reduce impact on the environment or climate", "Volunteered in an organisation tackling climate issues", "Signed a petition or contacted a politician regarding climate change", "Attended a public lecture, webinar or workshop about climate change", "Participation as an active member of an environmental organisation")
|
||
|
q40_levels <- c("No", "Yes")
|
||
|
q40_likert_table <- q40_data %>%
|
||
|
mutate(across(everything(),
|
||
|
factor, ordered = TRUE, levels = 0:1, labels=q40_levels)) %>%
|
||
|
as.data.frame %>%
|
||
|
likert
|
||
|
plot(q40_likert_table, wrap=25, text.size=3, ordered=TRUE, low.color='#B18839', high.color='#590048') +
|
||
|
labs(title = title, caption = NULL, y="") +
|
||
|
guides(fill = guide_legend(title = NULL)) +
|
||
|
theme_ipsum() +
|
||
|
theme(plot.title = element_text(lineheight = 0.9, size =12, hjust = 0))
|
||
|
# save to png file for reports
|
||
|
ggsave("figures/figure10.png", width = 20, height = 20, units = "cm")
|
||
|
install.packages("pdftables")
|
||
|
library(pdftables)
|
||
|
here
|
||
|
here()
|
||
|
library(here)
|
||
|
convert_pdf("gits/hesa_staff/Sheet1.pdf", "sheet.csv")
|
||
|
install.packages("UKCensusAPI")
|
||
|
install.packages("devtools")
|
||
|
devtools::install_github("virgesmith/UKCensusAPI")
|
||
|
RETICULATE_PYTHON=$(which python3)
|
||
|
library(UKCensusAPI)
|
||
|
install.packages("nomisr")
|
||
|
library(nomisr)
|
||
|
nomis_overview()
|
||
|
nomis_data_info()
|
||
|
nomis_search(name = census)
|
||
|
x <- nomis_search(name = "*census*")
|
||
|
View(x)
|
||
|
nomis_get_data(id = TS031)
|
||
|
x <- nomis_data_info()
|
||
|
x <- nomis_data_info()
|
||
|
View(x)
|
||
|
View(x[[5]][[203]])
|
||
|
head(x)
|
||
|
as.data.frame(x)
|
||
|
View(x[[5]][[314]])
|
||
|
View(x[[6]][[315]])
|
||
|
x <- nomis_data_info()library(dplyr)
|
||
|
library(dplyr)
|
||
|
x %>% filter(name.value %in% "ts030")
|
||
|
x %>% filter(name.value == "*ts030*")
|
||
|
x %>% filter(name.value == "%ts030%")
|
||
|
filtered_df <- filter(x, grepl("ts030")
|
||
|
)
|
||
|
filtered_df <- filter(x, grepl("ts030", name.value)
|
||
|
)
|
||
|
View(filtered_df)
|
||
|
filtered_df <- filter(x, grepl("030", name.value))
|
||
|
filtered_df <- filter(x, grepl("TS030", name.value))
|
||
|
View(filtered_df[[5]][[1]])
|
||
|
filtered_df <- filter(x, grepl("TS030", name.value))
|
||
|
View(filtered_df)
|
||
|
nomis_get_data(id=NM_2049_1)
|
||
|
nomis_get_data(id="NM_2049_1)
|
||
|
nomis_get_data(id="NM_2049_1")
|
||
|
```
|
||
|
```
|
||
|
View(x)
|
||
|
View(x[[5]][[1316]])
|
||
|
View(x[[6]][[1316]])
|
||
|
```
|
||
|
```
|
||
|
```
|
||
|
nomis_data_info("NM_2049_1")
|
||
|
y <- nomis_data_info("NM_2049_1")
|
||
|
tibble::glimpse(y)
|
||
|
```
|
||
|
library(here)
|
||
|
# R Setup -----------------------------------------------------------------
|
||
|
here::i_am("survey_analysis.R")
|
||
|
```
|
||
|
# R Setup -----------------------------------------------------------------
|
||
|
here::i_am("chapter_1.qmd")
|
||
|
# R Setup -----------------------------------------------------------------
|
||
|
here::i_am("//Users/kidwellj/gits/hacking_religion_textbook/hacking_religion/chapter_1.qmd")
|
||
|
# R Setup -----------------------------------------------------------------
|
||
|
here::i_am("//Users/kidwellj/gits/hacking_religion_textbook/hacking_religion/chapter_1.qmd")
|
||
|
# R Setup -----------------------------------------------------------------
|
||
|
here::i_am("/Users/kidwellj/gits/hacking_religion_textbook/hacking_religion/chapter_1.qmd")
|
||
|
# R Setup -----------------------------------------------------------------
|
||
|
here::i_am("kidwellj/gits/hacking_religion_textbook/hacking_religion/chapter_1.qmd")
|
||
|
library(here) # much better way to manage working paths in R across multiple instances
|
||
|
# R Setup -----------------------------------------------------------------
|
||
|
here::i_am("gits/hacking_religion_textbook/hacking_religion/chapter_1.qmd")
|
||
|
library(here) # much better way to manage working paths in R across multiple instances
|
||
|
# R Setup -----------------------------------------------------------------
|
||
|
here::i_am("hacking_religion_textbook/hacking_religion/chapter_1.qmd")
|
||
|
# R Setup -----------------------------------------------------------------
|
||
|
here::i_am("Users/kidwellj/gits/hacking_religion_textbook/hacking_religion/chapter_1.qmd")
|
||
|
library(here) # much better way to manage working paths in R across multiple instances
|
||
|
# R Setup -----------------------------------------------------------------
|
||
|
library(here) # much better way to manage working paths in R across multiple instances
|
||
|
here::i_am("hacking_religion_textbook/hacking_religion/chapter_1.qmd")
|
||
|
setwd("/Users/kidwellj/gits/hacking_religion_textbook/hacking_religion")
|
||
|
# R Setup -----------------------------------------------------------------
|
||
|
setwd("/Users/kidwellj/gits/hacking_religion_textbook/hacking_religion")
|
||
|
library(here) # much better way to manage working paths in R across multiple instances
|
||
|
here::i_am("hacking_religion_textbook/hacking_religion/chapter_1.qmd")
|
||
|
# R Setup -----------------------------------------------------------------
|
||
|
setwd("/Users/kidwellj/gits/hacking_religion_textbook/hacking_religion")
|
||
|
library(here) # much better way to manage working paths in R across multiple instances
|
||
|
here::i_am("hacking_religion/chapter_1.qmd")
|
||
|
if (dir.exists(here("data")) == FALSE) {
|
||
|
dir.create(here("data"))
|
||
|
}
|
||
|
religion_uk <- read_csv(here("example_data", "census2021-ts030-rgn.csv"))
|
||
|
religion_uk <- read.csv(here("example_data", "census2021-ts030-rgn.csv"))
|
||
|
religion_uk <- read.csv(here("example_data", "census2021-ts030-rgn.csv"))
|
||
|
# R Setup -----------------------------------------------------------------
|
||
|
setwd("/Users/kidwellj/gits/hacking_religion_textbook/hacking_religion")
|
||
|
library(here) # much better way to manage working paths in R across multiple instances
|
||
|
here::i_am("chapter_1.qmd")
|
||
|
religion_uk <- read.csv(here("example_data", "census2021-ts030-rgn.csv"))
|
||
|
View(religion_uk)
|
||
|
View(religion_uk)
|
||
|
# %>% select(Q0:Q68)
|
||
|
head(religion_uk)
|
||
|
```
|
||
|
```r
|
||
|
```
|
||
|
```
|
||
|
```
|
||
|
```
|
||
|
head(religion_uk)
|
||
|
```
|
||
|
```
|
||
|
```
|
||
|
```
|
||
|
```
|
||
|
# R Setup -----------------------------------------------------------------
|
||
|
setwd("/Users/kidwellj/gits/hacking_religion_textbook/hacking_religion")
|
||
|
library(here) # much better way to manage working paths in R across multiple instances
|
||
|
here::i_am("chapter_1.qmd")
|
||
|
dat(religion_uk)
|
||
|
summary(religion_uk)
|
||
|
tail(religion_uk)
|
||
|
```
|
||
|
```
|
||
|
```
|
||
|
```
|
||
|
# R Setup -----------------------------------------------------------------
|
||
|
library(here)
|
||
|
religion_uk <- read.csv(here("example_data", "census2021-ts030-rgn.csv"))
|
||
|
View(religion_uk)
|
||
|
head(religion_uk)
|
||
|
tail(religion_uk)
|
||
|
religion_uk <- read.csv(here("example_data", "census2021-ts030-rgn.csv"))
|
||
|
tail(religion_uk)
|
||
|
knitr::kable(head(religion_uk))
|
||
|
```
|
||
|
wmids_data <- select(religion_uk, no_religion:other)
|
||
|
library(tidyverse)
|
||
|
install.packages("tidyverse")
|
||
|
library(tidyverse)
|
||
|
wmids_data <- select(religion_uk, no_religion:other)
|
||
|
View(wmids_data)
|
||
|
View(wmids_data)
|
||
|
View(religion_uk)
|
||
|
wmids_data <- select(religion_uk, geography="West Midlands")
|
||
|
wmids_data <- select(religion_uk, geography='West Midlands')
|
||
|
wmids_data <- select(religion_uk, geography=='West Midlands')
|
||
|
View(religion_uk)
|
||
|
wmids_data <- select(religion_uk, geography=="West Midlands")
|
||
|
View(religion_uk)
|