library(tidyverse)
Employed scientists and engineers, by sex and occupation: 2019
<- readxl::read_excel("~/Documents/R/WomenInSTEM/nsb20212-tabslbr-024_scientists.xlsx",
scientists na = "0", skip = 3)
# View(scientists)
<- scientists[-1,]%>%
scientists1 ::clean_names() %>%#names
janitorrename(female_perc=x4,male_perc=x6) %>%
mutate(female=ifelse(female=="s",0,female),
female_perc=ifelse(female_perc=="s",0,female_perc),
male=ifelse(male=="s",0,male),
male_perc=ifelse(male_perc=="s",0,male_perc),
total=ifelse(total=="s",0,total)) %>%
mutate(across(-occupation,as.numeric)) %>%
filter(!occupation%in%c("All occupations"))
<- scientists1%>%
dfselect(female,male,total) %>%
filter(female>0,male>0,total>0)%>%
log10()
<-scientists1 %>%
col_df pivot_longer(cols = c(total,female,male),names_to="names",values_to="values")%>%
distinct()
# Add a new column with color
<- c('royalblue1', 'darkcyan', 'oldlace')
mycolors #scientists1$color <- mycolors
library(rgl)
plot3d(
x=df$female,
y=df$male,
z=df$total,
col = mycolors,
aspect=0.5,
lwd=2,
type = 'h',
radius = .1,
xlab="Female", ylab="Male", zlab="Total")
library(rayshader)
<-scientists1%>%
plotfilter(female>0,female_perc>0.00001,total>0) %>%
ggplot() +
geom_jitter(aes(x=total, y=female, color=log10(total))) +
scale_x_log10()+
scale_y_log10()+
scale_color_continuous(limits = c(0, 8))
plot_gg(plot,
#width = 3.5,
multicore = TRUE,
windowsize = c(800, 800))
# zoom = (0.85, phi = 35,
# theta = 30, sunangle = 225,
# soliddepth = -100)
= scientists1%>%
gg filter(female>0,male>0.00001,total>0) %>%
pivot_longer(cols = c(female,male),names_to="gender",values_to="values") %>%
ggplot(aes(x=total, y=values)) +
stat_density_2d(aes(fill = stat(nlevel)),
geom = "polygon",
n = 100,bins = 10,contour = TRUE) +
facet_wrap(gender~.) +
scale_fill_viridis_c(option = "A")
plot_gg(gg,multicore=TRUE,width=5,height=5,scale=250)
<- readxl::read_excel(here::here("WomenInStem/nsb20212-tabslbr-025_employed.xlsx"),
employed na = "0",
skip = 3)
# View(employed)
<- employed[-1,] %>%
employed1 ::clean_names()%>%#names
janitorrename(female_perc=x4,male_perc=x6,education=field_of_s_e_highest_degree) %>%
mutate(female=ifelse(female=="s",0,female),
female_perc=ifelse(female_perc=="s",0,female_perc),
male=ifelse(male=="s",0,male),
male_perc=ifelse(male_perc=="s",0,male_perc),
total=ifelse(total=="s",0,total)) %>%
mutate(across(-education,as.numeric)) %>%
arrange(education)
<-employed1 %>%
gg1 pivot_longer(cols = c(female,male),names_to="gender",values_to="values") %>%
ggplot(aes(x=total, y=values)) +
stat_density_2d(aes(fill = stat(nlevel)),
geom = "polygon",
n = 100,bins = 10,contour = TRUE) +
facet_wrap(gender~.) +
scale_fill_viridis_c(option = "B") +
labs(title="STEM education by gender",
caption="Dataviz: Federica Gazzelloni")+
::theme_economist_white()+
ggthemestheme(legend.position =c(0.2,-0.05),
legend.direction = "horizontal")
library(rayshader)
plot_gg(gg1,
multicore=TRUE,
#invert=TRUE,
width=5,height=5,
scale=250)
Sys.sleep(0.2)
render_snapshot(clear = TRUE)
= tempfile(fileext = ".hdr")
tempfilehdr download.file("https://www.tylermw.com/data/venice_sunset_2k.hdr",tempfilehdr)
plot_gg(gg1,
width = 5, height = 5,
scale = 250,
multicore = TRUE,
windowsize = c(1200, 960))
Sys.sleep(0.2)
# render_depth(focallength = 100,clear=TRUE)
render_highquality(samples = 256,
aperture=30,
light = FALSE,
focal_distance = 1700,
obj_material = rayrender::dielectric(attenuation = c(1,1,0.3)/200),
ground_material = rayrender::diffuse(checkercolor = "grey80",
sigma=90,
checkerperiod = 100),
environment_light = tempfilehdr,
camera_lookat = c(0,-150,0))