Last active
January 13, 2026 20:26
-
-
Save abikoushi/aa8b941c69ff1a1656f951fc1a37aabd to your computer and use it in GitHub Desktop.
スティーブン・ピンカー『人はどこまで合理的か 上』5章のタクシー問題に出てくるような図
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ##参考文献: | |
| ##スティーブン・ピンカー『人はどこまで合理的か 上』,5章,訳:橘明美,草思社 | |
| #devtools::install_github("abikoushi/ggsomestat") | |
| library(ggsomestat) | |
| library(dplyr) | |
| taxi <- matrix(c(0.68, 0.03, | |
| 0.17, 0.12), byrow = TRUE, nrow = 2) | |
| gb=c("green","blue") | |
| df_taxi<- expand.grid(sight=factor(gb, levels = gb), | |
| true=factor(gb, levels = gb)) | |
| df_taxi <- mutate(df_taxi, | |
| prob = c(taxi), | |
| facetdummy=1) | |
| df_taxi_b <- dplyr::filter(df_taxi, sight=="blue") %>% | |
| mutate(facetdummy=2) | |
| df_taxi2 <- bind_rows(df_taxi, df_taxi_b) | |
| p <- ggplot(df_taxi2, aes(x=prob*100, fill=interaction(sight,true, sep=", ")))+ | |
| stat_countgrid(geom="tile",colour="grey")+ | |
| facet_grid(~facetdummy)+ | |
| scale_fill_brewer(palette = "Blues")+ | |
| theme_classic(18) + | |
| coord_fixed() + | |
| labs(x="",y="", fill="sight, true") | |
| print(p) | |
| ggsave(plot = p, filename = "taxiplot.png", width = 8, height = 8) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment