R: 米国非白人の割合の推移, CGPfunctions ver. 1

Last Updated on October 25, 2020 by shibatau

スクリプトのメモです。後ほど整理します。

 

米国非白人の割合の推移を次のスクリプトにしたがってわかりやすいグラフにします。

 

Displaying increasing U.S. eligible voter diversity with a slopegraph in R

 

スクリプト。整理できていません。

 

# devtools::install_github("ibecav/CGPfunctions",
                         build_vignettes = TRUE,
                         upgrade = "ask",
                         force = TRUE)
library(CGPfunctions)
library(tidyverse)
library(stringr) # 不要な文字を削除するため
df3 <- read.table(pipe("pbpaste"), sep="\t", header=T)
df3_tibble <- as_tibble(df3)
df3_tibble
data <- df3_tibble %>% 
  select(State, contains("share")) %>% 
  tidyr::pivot_longer(cols = starts_with("White.share"), 
                      names_to = "year", 
                      values_to = "percent",
                      names_pattern = "([0-9]{4})"
                      )
percent2 <- stringr::str_sub(data$percent, end=-2)
# add percent to data
data2 <- data %>% 
  add_column(percent2)
data2$percent2 <- as.integer(data2$percent2)
data3 <- data2 %>% mutate(percent2 = as.integer(100 - percent2))
data3

newggslopegraph(dataframe = data3, 
                Times = year, 
                Measurement = percent2, 
                Grouping = State,
                Title = "Eligible non-white voters per state 2000- 2018",
                SubTitle = "Expressed as a percent of total eligible voters",
                Caption = "Retrieved from https://www.pewresearch.org/2020/09/23/the-changing-racial-and-ethnic-composition-of-the-u-s-electorate/ on Oct 23, 2020")
                      

 

About shibatau

I was born and grown up in Kyoto. I studied western philosophy at the University and specialized in analytic philosophy, especially Ludwig Wittgenstein at the postgraduate school. I'm interested in new technology, especially machine learning and have been learning R language for two years and began to learn Python last summer. Listening toParamore, Sia, Amazarashi and MIyuki Nakajima. Favorite movies I've recently seen: "FREEHELD". Favorite actors and actresses: Anthony Hopkins, Denzel Washington, Ellen Page, Meryl Streep, Mia Wasikowska and Robert DeNiro. Favorite books: Fyodor Mikhailovich Dostoyevsky, "The Karamazov Brothers", Shinran, "Lamentations of Divergences". Favorite phrase: Salvation by Faith. Twitter: @shibatau

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.