.Rhistory 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  1. status == "healthy" && mammogram == "+ve" ~ "incorrect"),
  2. status = fct_reorder(status,"healthy"))
  3. d <- tibble::tibble(age = age,
  4. status = c(rep("cancer", n*p_cancer),
  5. rep("healthy", n*(1-p_cancer))),
  6. mammogram = c(rep("+ve", n_c_p ),
  7. rep("-ve", n_c_n ),
  8. rep("+ve", n_h_p ) ,
  9. rep("-ve", n_h_n ))
  10. )
  11. d <- d %>%
  12. mutate(diagnosis = case_when(status == "cancer" && mammogram == "+ve" ~ "correct",
  13. status == "cancer" && mammogram == "-ve" ~ "incorrect",
  14. status == "healthy" && mammogram == "-ve" ~ "correct",
  15. status == "healthy" && mammogram == "+ve" ~ "incorrect"),
  16. status = fct_reorder(status,"healthy"))
  17. g1 <- ggplot(d, aes(area = age, fill = status)) +
  18. geom_treemap(layout="fixed") + scale_fill_brewer()
  19. g2 <- ggplot(d, aes(area = age, fill = mammogram)) +
  20. geom_treemap(layout="fixed") + scale_fill_brewer()
  21. g1
  22. g2
  23. g1 <- ggplot(d, aes(area = age, fill = status)) +
  24. geom_treemap() + scale_fill_brewer()
  25. g2 <- ggplot(d, aes(area = age, fill = mammogram)) +
  26. geom_treemap() + scale_fill_brewer()
  27. g1
  28. g2
  29. d <- d %>%
  30. mutate(diagnosis = case_when(status == "cancer" && mammogram == "+ve" ~ "correct",
  31. status == "cancer" && mammogram == "-ve" ~ "incorrect",
  32. status == "healthy" && mammogram == "-ve" ~ "correct",
  33. status == "healthy" && mammogram == "+ve" ~ "incorrect"),
  34. status = fct_reorder(status,"healthy", "cancer"),
  35. diagnosis = fct_reorder(status,"-ve", "+ve"))
  36. d <- d %>%
  37. mutate(diagnosis = case_when(status == "cancer" && mammogram == "+ve" ~ "correct",
  38. status == "cancer" && mammogram == "-ve" ~ "incorrect",
  39. status == "healthy" && mammogram == "-ve" ~ "correct",
  40. status == "healthy" && mammogram == "+ve" ~ "incorrect"),
  41. status = fct_reorder(status,"healthy", "cancer"),
  42. diagnosis = fct_reorder(diagnosis,"-ve", "+ve"))
  43. d <- tibble::tibble(age = age,
  44. status = c(rep("cancer", n*p_cancer),
  45. rep("healthy", n*(1-p_cancer))),
  46. mammogram = c(rep("+ve", n_c_p ),
  47. rep("-ve", n_c_n ),
  48. rep("+ve", n_h_p ) ,
  49. rep("-ve", n_h_n ))
  50. )
  51. d <- d %>%
  52. mutate(diagnosis = case_when(status == "cancer" && mammogram == "+ve" ~ "correct",
  53. status == "cancer" && mammogram == "-ve" ~ "incorrect",
  54. status == "healthy" && mammogram == "-ve" ~ "correct",
  55. status == "healthy" && mammogram == "+ve" ~ "incorrect"),
  56. status = fct_reorder(status,"healthy", "cancer"),
  57. mammogram = fct_reorder(mammpgram,"-ve", "+ve"))
  58. #
  59. library(tidyverse)
  60. library(ggbeeswarm)
  61. # library(cowplot)
  62. library(treemapify)
  63. n <- 1000
  64. age <- base::sample(35:45, n, replace=TRUE)
  65. p_cancer <- 0.01
  66. p_test_positive <- 0.8
  67. p_test_false_positive <- 0.1
  68. n_cancer <- n*p_cancer
  69. n_c_p <- n_cancer*p_test_positive
  70. n_c_n <- n_cancer - n_c_p
  71. n_h_p <- (n-n_cancer)*p_test_false_positive
  72. n_h_n <- (n-n_cancer) - n_h_p
  73. d <- tibble::tibble(age = age,
  74. status = c(rep("cancer", n*p_cancer),
  75. rep("healthy", n*(1-p_cancer))),
  76. mammogram = c(rep("+ve", n_c_p ),
  77. rep("-ve", n_c_n ),
  78. rep("+ve", n_h_p ) ,
  79. rep("-ve", n_h_n ))
  80. )
  81. d <- d %>%
  82. mutate(diagnosis = case_when(status == "cancer" && mammogram == "+ve" ~ "correct",
  83. status == "cancer" && mammogram == "-ve" ~ "incorrect",
  84. status == "healthy" && mammogram == "-ve" ~ "correct",
  85. status == "healthy" && mammogram == "+ve" ~ "incorrect"),
  86. status = fct_reorder(status,"healthy", "cancer"),
  87. mammogram = fct_reorder(mammpgram,"-ve", "+ve"))
  88. ?fct_relevel
  89. d <- d %>%
  90. mutate(diagnosis = case_when(status == "cancer" && mammogram == "+ve" ~ "correct",
  91. status == "cancer" && mammogram == "-ve" ~ "incorrect",
  92. status == "healthy" && mammogram == "-ve" ~ "correct",
  93. status == "healthy" && mammogram == "+ve" ~ "incorrect"),
  94. status = fct_relevel(status,"healthy", "cancer"),
  95. mammogram = fct_relevel(mammpgram,"-ve", "+ve"))
  96. d <- d %>%
  97. mutate(diagnosis = case_when(status == "cancer" && mammogram == "+ve" ~ "correct",
  98. status == "cancer" && mammogram == "-ve" ~ "incorrect",
  99. status == "healthy" && mammogram == "-ve" ~ "correct",
  100. status == "healthy" && mammogram == "+ve" ~ "incorrect"),
  101. status = fct_relevel(status,"healthy", "cancer"),
  102. mammogram = fct_relevel(mammogram,"-ve", "+ve"))
  103. g1 <- ggplot(d, aes(area = age, fill = status)) +
  104. geom_treemap() + scale_fill_brewer()
  105. g2 <- ggplot(d, aes(area = age, fill = mammogram)) +
  106. geom_treemap() + scale_fill_brewer()
  107. g1
  108. g2
  109. g3 <- ggplot(d, aes(area = age, fill = diagnosis)) +
  110. geom_treemap() + scale_fill_brewer(palette = "Set2")
  111. g3
  112. d <- d %>%
  113. mutate(diagnosis = case_when(status == "cancer" & mammogram == "+ve" ~ "correct",
  114. status == "cancer" & mammogram == "-ve" ~ "incorrect",
  115. status == "healthy" & mammogram == "-ve" ~ "correct",
  116. status == "healthy" & mammogram == "+ve" ~ "incorrect"),
  117. status = fct_relevel(status,"healthy", "cancer"),
  118. mammogram = fct_relevel(mammogram,"-ve", "+ve"))
  119. g3 <- ggplot(d, aes(area = age, fill = diagnosis)) +
  120. geom_treemap() + scale_fill_brewer(palette = "Set2")
  121. g3
  122. g3 <- ggplot(d, aes(area = age, group, status, fill = diagnosis)) +
  123. geom_treemap() + scale_fill_brewer(palette = "Set2")
  124. g3
  125. g3 <- ggplot(d, aes(area = age, group= status, fill = diagnosis)) +
  126. geom_treemap() + scale_fill_brewer(palette = "Set2")
  127. g3
  128. g3 <- ggplot(d, aes(area = age, group= status, fill = diagnosis)) +
  129. geom_treemap(layout="fixed") + scale_fill_brewer(palette = "Set2")
  130. g3
  131. g3 <- ggplot(d, aes(area = age, color= status, fill = diagnosis)) +
  132. geom_treemap(layout="fixed") + scale_fill_brewer(palette = "Set2")
  133. g3
  134. g3 <- ggplot(d, aes(area = age, width= status, fill = diagnosis)) +
  135. geom_treemap(layout="fixed") + scale_fill_brewer(palette = "Set2")
  136. g3
  137. ?geom_treemap
  138. g3 <- ggplot(d, aes(area = age, alpha= status, fill = diagnosis)) +
  139. geom_treemap(layout="fixed") + scale_fill_brewer(palette = "Set2")
  140. g3
  141. g1
  142. g2
  143. g3
  144. ?ggsave()
  145. ggsave("plot1.pdf", g1)
  146. ggsave("plot2.pdf", g2)
  147. ggsave("plot3.pdf", g3)
  148. source('~/OneDrive - The University of Nottingham/teaching/2019-tutorials/2019-11-17-bayes/bayes-bee-plot.R', echo=TRUE)
  149. ggsave("plot1.png", g1)
  150. ggsave("plot2.png", g2)
  151. ggsave("plot3.png", g3)
  152. #
  153. colorPalette <- "Set3"
  154. g1 <- ggplot(d, aes(area = age, fill = status)) +
  155. geom_treemap() + scale_fill_brewer(palette = colorPalette)
  156. g2 <- ggplot(d, aes(area = age, fill = mammogram)) +
  157. geom_treemap() + scale_fill_brewer(palette = colorPalette)
  158. g3 <- ggplot(d, aes(area = age, alpha=status, fill = diagnosis)) +
  159. geom_treemap(layout="fixed") + scale_fill_brewer(palette = "Set2") +
  160. scale_alpha_discrete(range = c(0.3, 1.o))
  161. g3 <- ggplot(d, aes(area = age, alpha=status, fill = diagnosis)) +
  162. geom_treemap(layout="fixed") + scale_fill_brewer(palette = "Set2") +
  163. scale_alpha_discrete(range = c(0.3, 1.0))
  164. ggsave("plot1.png", g1)
  165. ggsave("plot2.png", g2)
  166. ggsave("plot3.png", g3)
  167. ?scale_fill_brewer
  168. #
  169. colorPalette <- "Accent"
  170. g1 <- ggplot(d, aes(area = age, fill = status)) +
  171. geom_treemap() + scale_fill_brewer(palette = colorPalette)
  172. g2 <- ggplot(d, aes(area = age, fill = mammogram)) +
  173. geom_treemap() + scale_fill_brewer(palette = colorPalette)
  174. g3 <- ggplot(d, aes(area = age, alpha=status, fill = diagnosis)) +
  175. geom_treemap(layout="fixed") + scale_fill_brewer(palette = "Set2") +
  176. scale_alpha_discrete(range = c(0.3, 1.0))
  177. ggsave("plot1.png", g1)
  178. ggsave("plot2.png", g2)
  179. #
  180. colorPalette <- "Dark2"
  181. g1 <- ggplot(d, aes(area = age, fill = status)) +
  182. geom_treemap() + scale_fill_brewer(palette = colorPalette)
  183. g2 <- ggplot(d, aes(area = age, fill = mammogram)) +
  184. geom_treemap() + scale_fill_brewer(palette = colorPalette)
  185. ggsave("plot1.png", g1)
  186. ggsave("plot2.png", g2)
  187. #
  188. colorPalette <- "Pastel1"
  189. g1 <- ggplot(d, aes(area = age, fill = status)) +
  190. geom_treemap() + scale_fill_brewer(palette = colorPalette)
  191. g2 <- ggplot(d, aes(area = age, fill = mammogram)) +
  192. geom_treemap() + scale_fill_brewer(palette = colorPalette)
  193. ggsave("plot1.png", g1)
  194. ggsave("plot2.png", g2)
  195. #
  196. colorPalette <- "Set3"
  197. g1 <- ggplot(d, aes(area = age, fill = status)) +
  198. geom_treemap() + scale_fill_brewer(palette = colorPalette)
  199. g2 <- ggplot(d, aes(area = age, fill = mammogram)) +
  200. geom_treemap() + scale_fill_brewer(palette = colorPalette)
  201. ggsave("plot1.png", g1)
  202. ggsave("plot2.png", g2)
  203. #
  204. colorPalette <- "Set1"
  205. g1 <- ggplot(d, aes(area = age, fill = status)) +
  206. geom_treemap() + scale_fill_brewer(palette = colorPalette)
  207. g2 <- ggplot(d, aes(area = age, fill = mammogram)) +
  208. geom_treemap() + scale_fill_brewer(palette = colorPalette)
  209. ggsave("plot1.png", g1)
  210. ggsave("plot2.png", g2)
  211. g1 <- ggplot(d, aes(area = age, fill = status)) +
  212. geom_treemap() + scale_fill_brewer()
  213. ggsave("plot1.png", g1)
  214. g2 <- ggplot(d, aes(area = age, fill = mammogram)) +
  215. geom_treemap() + scale_fill_brewer()
  216. ggsave("plot1.png", g1)
  217. ggsave("plot2.png", g2)
  218. g3 <- ggplot(d, aes(area = age, alpha=status, fill = diagnosis)) +
  219. geom_treemap(layout="fixed") + scale_fill_brewer(palette = "Set2") +
  220. scale_alpha_discrete(range = c(0.6, 1.0))
  221. ggsave("plot3.png", g3)
  222. install.packages("reticulate")
  223. library(reticulate)
  224. use_python("/usr/local/bin/python3")
  225. reticulate::repl_python()
  226. knitr::opts_chunk$set(echo = TRUE)
  227. library(reticulate)
  228. use_python("/usr/local/bin/python3")
  229. summary(cars)
  230. library(tidyverse)
  231. ?qplot
  232. qplot(speed, distance, cars)
  233. glimpse(cars)
  234. qplot(speed, distance, data=cars)
  235. qplot(speed, dist, data=cars)
  236. cars
  237. with(cars, lm(dist~speed))
  238. install.packages("matlabr")
  239. install.packages("reticulate")
  240. library("reticulate")
  241. Sys.which("python")
  242. library(reticulate)
  243. use_python("/usr/local/bin/python3")
  244. repl_python()
  245. plumber::plumb(file='r/speech-to-text/api/define_api.R')$run()
  246. plumber::plumb(file='r/speech-to-text/api/define_api.R')$run()
  247. plumber::plumb(file='r/speech-to-text/api/define_api.R')$run()
  248. plumber::plumb(file='r/speech-to-text/api/define_api.R')$run()
  249. plumber::plumb(file='r/speech-to-text/api/define_api.R')$run()
  250. plumber::plumb(file='r/speech-to-text/api/define_api.R')$run()
  251. plumber::plumb(file='r/speech-to-text/api/define_api.R')$run()
  252. plumber::plumb(file='r/speech-to-text/api/define_api.R')$run()
  253. install.packages("tidyverse")
  254. install.packages("tidyverse")
  255. plumber::plumb(file='r/speech-to-text/api/define_api.R')$run()
  256. plumber::plumb(file='r/speech-to-text/api/define_api.R')$run()
  257. plumber::plumb(file='r/speech-to-text/api/define_api.R')$run()
  258. plumber::plumb(file='r/speech-to-text/api/define_api.R')$run()
  259. plumber::plumb(file='r/speech-to-text/api/define_api.R')$run()
  260. plumber::plumb(file='r/speech-to-text/api/define_api.R')$run()
  261. setwd()
  262. setwd('~')
  263. devtools::install_github('rstudio/bookdown')
  264. install.packages("gapminder")
  265. source('~/OneDrive - The University of Nottingham/teaching/_ug/2020-3rd-year-projects/example.R', echo=TRUE)
  266. 1+1
  267. "asf"
  268. 124*23
  269. meaningOfLife <- 42
  270. meaningOfLife * 2
  271. require(tidyverse)
  272. require(jsonlite)
  273. source("./perimetry_helpers.R")
  274. setwd("~/The University of Nottingham/Anthony's PhD Team - strkvis_pub_archive/strkvis-mri/code")
  275. require(tidyverse)
  276. require(jsonlite)
  277. source("./perimetry_helpers.R")
  278. # example file
  279. data_fname <- "../perimetry/sub-14196-perimetry-data.json"
  280. read_medmont(data_fname) %>%
  281. plot_medmont()
  282. plot_medmont <- function(the_points) {
  283. # NB-- the coord_polar step requires setting the starting point for 0 radians / 0 degrees...
  284. # to be offset from 12 o'clock
  285. the_points %>%
  286. mutate(
  287. xcoord = ecc * cos(pa),
  288. ycoord = ecc * sin(pa)
  289. ) %>%
  290. filter(State != "TS_UNTESTED") %>%
  291. ggplot(aes(x = ecc, y = pa, size = Value, symbol=State)) +
  292. geom_point(alpha = 0.9) +
  293. coord_fixed() +
  294. scale_colour_manual(values = c("red", "black", "gray")) + # "TS_SEEN" "TS_UNTESTED" "TS_NOT_SEEN"
  295. # coord_polar is kind of broken...
  296. # https://community.rstudio.com/t/making-coord-polar-behave-like-standard-polar-coordinate-plotting/3762/6
  297. # coord_polar(theta = "x", start = -pi/4, direction = -1) +
  298. theme_minimal()
  299. }
  300. read_medmont(data_fname) %>%
  301. plot_medmont()
  302. the_points %>%
  303. mutate(
  304. xcoord = ecc * cos(pa),
  305. ycoord = ecc * sin(pa)
  306. ) %>%
  307. filter(State != "TS_UNTESTED") %>%
  308. ggplot(aes(x = ecc, y = pa, size = Value, symbol=State)) +
  309. geom_point(alpha = 0.9) +
  310. coord_fixed() +
  311. scale_colour_manual(values = c("red", "black", "gray")) + # "TS_SEEN" "TS_UNTESTED" "TS_NOT_SEEN"
  312. # coord_polar is kind of broken...
  313. # https://community.rstudio.com/t/making-coord-polar-behave-like-standard-polar-coordinate-plotting/3762/6
  314. coord_polar(theta = "x", start = -pi/4, direction = -1) +
  315. theme_minimal()
  316. plot_medmont <- function(the_points) {
  317. # NB-- the coord_polar step requires setting the starting point for 0 radians / 0 degrees...
  318. # to be offset from 12 o'clock
  319. the_points %>%
  320. mutate(
  321. xcoord = ecc * cos(pa),
  322. ycoord = ecc * sin(pa)
  323. ) %>%
  324. filter(State != "TS_UNTESTED") %>%
  325. ggplot(aes(x = ecc, y = pa, size = Value, symbol=State)) +
  326. geom_point(alpha = 0.9) +
  327. coord_fixed() +
  328. scale_colour_manual(values = c("red", "black", "gray")) + # "TS_SEEN" "TS_UNTESTED" "TS_NOT_SEEN"
  329. # coord_polar is kind of broken...
  330. # https://community.rstudio.com/t/making-coord-polar-behave-like-standard-polar-coordinate-plotting/3762/6
  331. coord_polar(theta = "x", start = -pi/4, direction = -1) +
  332. theme_minimal()
  333. }
  334. read_medmont(data_fname) %>%
  335. plot_medmont()
  336. plot_medmont <- function(the_points) {
  337. # NB-- the coord_polar step requires setting the starting point for 0 radians / 0 degrees...
  338. # to be offset from 12 o'clock
  339. the_points %>%
  340. mutate(
  341. xcoord = ecc * cos(pa),
  342. ycoord = ecc * sin(pa)
  343. ) %>%
  344. filter(State != "TS_UNTESTED") %>%
  345. ggplot(aes(x = pa, y = ecc, size = Value, symbol=State)) +
  346. geom_point(alpha = 0.9) +
  347. # coord_fixed() +
  348. scale_colour_manual(values = c("red", "black", "gray")) + # "TS_SEEN" "TS_UNTESTED" "TS_NOT_SEEN"
  349. # coord_polar is kind of broken...
  350. # https://community.rstudio.com/t/making-coord-polar-behave-like-standard-polar-coordinate-plotting/3762/6
  351. coord_polar(theta = "x", start = -pi/4, direction = -1) +
  352. theme_minimal()
  353. }
  354. read_medmont(data_fname) %>%
  355. plot_medmont()
  356. coord_polar
  357. >coord_polar
  358. ?
  359. coord_polar
  360. plot_medmont <- function(the_points) {
  361. # NB-- the coord_polar step requires setting the starting point for 0 radians / 0 degrees...
  362. # to be offset from 12 o'clock
  363. the_points %>%
  364. mutate(
  365. xcoord = ecc * cos(pa),
  366. ycoord = ecc * sin(pa)
  367. ) %>%
  368. filter(State != "TS_UNTESTED") %>%
  369. ggplot(aes(x = pa, y = ecc, size = Value, symbol=State)) +
  370. geom_point(alpha = 0.9) +
  371. coord_fixed() +
  372. scale_colour_manual(values = c("red", "black", "gray")) + # "TS_SEEN" "TS_UNTESTED" "TS_NOT_SEEN"
  373. # coord_polar is kind of broken...
  374. # https://community.rstudio.com/t/making-coord-polar-behave-like-standard-polar-coordinate-plotting/3762/6
  375. coord_polar(theta = "x", start = -pi/4, direction = -1) +
  376. theme_minimal()
  377. }
  378. read_medmont(data_fname) %>%
  379. plot_medmont()
  380. plot_medmont(data)
  381. data <- read_medmont(data_fname)
  382. plot_medmont(data)
  383. the_points %>%
  384. mutate(
  385. pa_rad = pi * pa / 180.0,
  386. xcoord = ecc * cos(pa_rad),
  387. ycoord = ecc * sin(pa_rad)
  388. ) %>%
  389. filter(State != "TS_UNTESTED") %>%
  390. ggplot(aes(x = pa_rad, y = ecc, size = Value, symbol=State)) +
  391. geom_point(alpha = 0.9) +
  392. coord_fixed() +
  393. scale_colour_manual(values = c("red", "black", "gray")) + # "TS_SEEN" "TS_UNTESTED" "TS_NOT_SEEN"
  394. # coord_polar is kind of broken...
  395. # https://community.rstudio.com/t/making-coord-polar-behave-like-standard-polar-coordinate-plotting/3762/6
  396. coord_polar(theta = "x", start = -pi/4, direction = -1) +
  397. theme_minimal()
  398. data <- read_medmont(data_fname)
  399. plot_medmont(data)
  400. require(tidyverse)
  401. require(jsonlite)
  402. source("./perimetry_helpers.R")
  403. # example file
  404. data_fname <- "../perimetry/sub-14196-perimetry-data.json"
  405. data <- read_medmont(data_fname)
  406. plot_medmont(data)
  407. require(tidyverse)
  408. require(jsonlite)
  409. source("./perimetry_helpers.R")
  410. # example file
  411. data_fname <- "../perimetry/sub-14196-perimetry-data.json"
  412. data <- read_medmont(data_fname)
  413. #' convert medmont JSON to data frame
  414. #'
  415. #' returns
  416. #' list(result, the_points, d)
  417. #'
  418. read_medmont <- function(fname) {
  419. # get data
  420. j <- jsonlite::read_json(fname)
  421. d <- fromJSON(fname)
  422. # unpack what’s in JSON structure -----------------------------------------
  423. exam <- d$MedmontStudioExportFile[4]
  424. test <- exam$M600ThresholdExam$ThresholdTest$Test
  425. # e.g.
  426. # test$BlindSpot
  427. # Now look for the experiment data ----------------------------------------
  428. # test points are inside here
  429. n_points <- parse_integer(test$TestPoints$elements)
  430. the_points <- test$TestPoints$ThresholdTestPoint
  431. # exporting to CSV (tidy) style format --------------------------------------
  432. # this is how two write out a subset to CSV file...
  433. # make sure to take last set of measurements (if it's a list)
  434. # also length less than 5 (which is the right order of mag for ATTEMPTS, rather than points)
  435. # if there is only 1 test, a previous version of the check didn't seem to do the right thing/
  436. if (is_list(the_points) && length(the_points) < 5) {
  437. the_points <- the_points[[length(the_points)]]
  438. }
  439. result <- the_points %>%
  440. mutate(
  441. ecc = parse_double(Position$Ring),
  442. pa = parse_double(Position$Meridian),
  443. pa_rad = pi* pa / 180,
  444. Value = parse_double(Value)
  445. )
  446. }
  447. data <- read_medmont(data_fname)
  448. the_points %>%
  449. mutate(
  450. xcoord = ecc * cos(pa_rad),
  451. ycoord = ecc * sin(pa_rad)
  452. ) %>%
  453. filter(State != "TS_UNTESTED") %>%
  454. ggplot(aes(x = pa_rad, y = ecc, size = Value, symbol=State)) +
  455. geom_point(alpha = 0.9) +
  456. scale_colour_manual(values = c("red", "black", "gray")) + # "TS_SEEN" "TS_UNTESTED" "TS_NOT_SEEN"
  457. # coord_polar is kind of broken...
  458. # https://community.rstudio.com/t/making-coord-polar-behave-like-standard-polar-coordinate-plotting/3762/6
  459. coord_polar(theta = "x", start = -pi/4, direction = -1) +
  460. theme_minimal()
  461. ?coord_polar
  462. source("./perimetry_helpers.R")
  463. # example file
  464. data_fname <- "../perimetry/sub-14196-perimetry-data.json"
  465. data <- read_medmont(data_fname)
  466. plot_medmont(data)
  467. plot_medmont <- function(the_points) {
  468. # NB-- the coord_polar step requires setting the starting point for 0 radians / 0 degrees...
  469. # to be offset from 12 o'clock
  470. the_points %>%
  471. mutate(
  472. xcoord = ecc * cos(pa_rad),
  473. ycoord = ecc * sin(pa_rad)
  474. ) %>%
  475. filter(State != "TS_UNTESTED") %>%
  476. ggplot(aes(x = xcoord, y = ycoord, size = Value, symbol=State)) +
  477. geom_point(alpha = 0.9) +
  478. coord_fixed() +
  479. scale_colour_manual(values = c("red", "black", "gray")) + # "TS_SEEN" "TS_UNTESTED" "TS_NOT_SEEN"
  480. # coord_polar is kind of broken...
  481. # https://community.rstudio.com/t/making-coord-polar-behave-like-standard-polar-coordinate-plotting/3762/6
  482. # coord_polar(theta = "x", start = -pi/4, direction = -1) +
  483. theme_minimal()
  484. }
  485. source("./perimetry_helpers.R")
  486. # example file
  487. data_fname <- "../perimetry/sub-14196-perimetry-data.json"
  488. data <- read_medmont(data_fname)
  489. plot_medmont(data)
  490. plot_medmont <- function(the_points) {
  491. # NB-- the coord_polar step requires setting the starting point for 0 radians / 0 degrees...
  492. # to be offset from 12 o'clock
  493. the_points %>%
  494. mutate(
  495. xcoord = ecc * cos(pa_rad),
  496. ycoord = ecc * sin(pa_rad)
  497. ) %>%
  498. filter(State != "TS_UNTESTED") %>%
  499. ggplot(aes(x = xcoord, y = ycoord, size = Value, colour=State)) +
  500. geom_point(alpha = 0.9) +
  501. coord_fixed() +
  502. scale_colour_manual(values = c("red", "black", "gray")) + # "TS_SEEN" "TS_UNTESTED" "TS_NOT_SEEN"
  503. # coord_polar is kind of broken...
  504. # https://community.rstudio.com/t/making-coord-polar-behave-like-standard-polar-coordinate-plotting/3762/6
  505. # coord_polar(theta = "x", start = -pi/4, direction = -1) +
  506. theme_minimal()
  507. }
  508. plot_medmont(data)
  509. # example file
  510. data_fname <- "../perimetry/sub-14326-perimetry-data.json"
  511. data <- read_medmont(data_fname)
  512. plot_medmont(data)