Skip to content

Instantly share code, notes, and snippets.

@abikoushi
Created February 19, 2025 13:35
Show Gist options
  • Save abikoushi/773711d26600a810a154a55224270744 to your computer and use it in GitHub Desktop.
Save abikoushi/773711d26600a810a154a55224270744 to your computer and use it in GitHub Desktop.
pdftools example
library(pdftools)
library(tidyr)
library(dplyr)
library(ggplot2)
browseURL("https://www.jstage.jst.go.jp/article/jph/50/8/50_686/_article/-char/ja/")
text = pdf_text("~/Downloads/50_686.pdf")
tab2raw = unlist(strsplit(text[grep("表2", text)]," "))
tab2raw = tab2raw[sapply(tab2raw, nchar) > 0]
tab2raw = tab2raw[16:145]
tab2 = tab2raw[-c(15:19, 27:29,
37:39, 47:49,
57:61, 69:75,
83:87, 95:101,
109:112,120:124)]
tab2 = tab2[-grep("月",tab2)]
numtab2 = as.integer(gsub(" |\n","", tab2))
mat2 = matrix(numtab2,ncol=6, byrow = TRUE)
mat2 = mat2[,c(1,3,5)]
colnames(mat2) <- c("野宿生活者", "簡易生活者", "総数")
df_2 = as.data.frame(mat2[,-3]) %>%
mutate(month=1:12) %>%
pivot_longer(1:2)
ggplot(df_2, aes(x=factor(month), y=value, colour=name, group=name))+
geom_area(alpha=0.1, position = "identity")+
labs(x="発見月", y="人数", colour="",
title="ホームレス者死亡の発見月(逢坂他, 2003)")+
theme_classic(15,"osaka")
#ggsave("line.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment