jcheng5 commited on
Commit
ef83b17
·
1 Parent(s): 1e06b58

Add marginal plots, filtering by species

Browse files
Files changed (3) hide show
  1. app.R +26 -4
  2. renv.lock +192 -0
  3. examples.Rproj → simplepenguins.Rproj +0 -0
app.R CHANGED
@@ -4,14 +4,20 @@ library(dplyr)
4
  library(ggplot2)
5
 
6
  df <- readr::read_csv("penguins.csv")
 
7
 
8
  ui <- page_fillable(theme = bs_theme(bootswatch = "minty"),
9
  layout_sidebar(fillable = TRUE,
10
  sidebar(
11
  varSelectInput("xvar", "X variable", df, selected = "Bill Length (mm)"),
12
  varSelectInput("yvar", "Y variable", df, selected = "Bill Depth (mm)"),
 
 
 
 
 
 
13
  checkboxInput("smooth", "Add smoother"),
14
- checkboxInput("species", "By species", TRUE)
15
  ),
16
  plotOutput("scatter")
17
  )
@@ -19,13 +25,29 @@ ui <- page_fillable(theme = bs_theme(bootswatch = "minty"),
19
 
20
  server <- function(input, output, session) {
21
  subsetted <- reactive({
22
- df |> select(!!input$xvar, !!input$yvar, "Species")
 
23
  })
24
 
25
  output$scatter <- renderPlot({
26
- ggplot(subsetted(), aes(!!input$xvar, !!input$yvar)) +
27
- geom_point(if (input$species) aes(color=Species)) +
 
 
28
  if (input$smooth) geom_smooth()
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  }, res = 100)
30
  }
31
 
 
4
  library(ggplot2)
5
 
6
  df <- readr::read_csv("penguins.csv")
7
+ species <- unique(df$Species)
8
 
9
  ui <- page_fillable(theme = bs_theme(bootswatch = "minty"),
10
  layout_sidebar(fillable = TRUE,
11
  sidebar(
12
  varSelectInput("xvar", "X variable", df, selected = "Bill Length (mm)"),
13
  varSelectInput("yvar", "Y variable", df, selected = "Bill Depth (mm)"),
14
+ checkboxGroupInput(
15
+ "species", "Filter by species", species, selected = species
16
+ ),
17
+ hr(),
18
+ checkboxInput("by_species", "Show species", TRUE),
19
+ checkboxInput("show_margins", "Show marginal plots", TRUE),
20
  checkboxInput("smooth", "Add smoother"),
 
21
  ),
22
  plotOutput("scatter")
23
  )
 
25
 
26
  server <- function(input, output, session) {
27
  subsetted <- reactive({
28
+ req(input$species)
29
+ df |> filter(Species %in% input$species)
30
  })
31
 
32
  output$scatter <- renderPlot({
33
+ p <- ggplot(subsetted(), aes(!!input$xvar, !!input$yvar)) + list(
34
+ theme(legend.position = "bottom"),
35
+ if (input$by_species) aes(color=Species),
36
+ geom_point(),
37
  if (input$smooth) geom_smooth()
38
+ )
39
+
40
+ if (input$show_margins) {
41
+ p <- ggExtra::ggMarginal(
42
+ p,
43
+ type = if (input$by_species) "density" else "histogram",
44
+ margins = "both",
45
+ size = 8,
46
+ groupColour = input$by_species,
47
+ groupFill = input$by_species
48
+ )
49
+ }
50
+ p
51
  }, res = 100)
52
  }
53
 
renv.lock CHANGED
@@ -187,6 +187,24 @@
187
  ],
188
  "Hash": "f20c47fd52fae58b4e377c37bb8c335b"
189
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
190
  "commonmark": {
191
  "Package": "commonmark",
192
  "Version": "1.9.0",
@@ -274,6 +292,17 @@
274
  ],
275
  "Hash": "bb0eec2fe32e88d9e2836c2f73ea2077"
276
  },
 
 
 
 
 
 
 
 
 
 
 
277
  "fansi": {
278
  "Package": "fansi",
279
  "Version": "1.0.4",
@@ -334,6 +363,27 @@
334
  ],
335
  "Hash": "15e9634c0fcd294799e9b2e929ed1b86"
336
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
337
  "ggplot2": {
338
  "Package": "ggplot2",
339
  "Version": "3.4.2",
@@ -385,6 +435,17 @@
385
  ],
386
  "Hash": "b44addadb528a0d227794121c00572a0"
387
  },
 
 
 
 
 
 
 
 
 
 
 
388
  "hms": {
389
  "Package": "hms",
390
  "Version": "1.1.3",
@@ -416,6 +477,21 @@
416
  ],
417
  "Hash": "ba0240784ad50a62165058a27459304a"
418
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
419
  "httpuv": {
420
  "Package": "httpuv",
421
  "Version": "1.6.9",
@@ -462,6 +538,22 @@
462
  ],
463
  "Hash": "a4269a09a9b865579b2635c77e572374"
464
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
465
  "labeling": {
466
  "Package": "labeling",
467
  "Version": "0.4.2",
@@ -560,6 +652,18 @@
560
  ],
561
  "Hash": "18e9c28c1d3ca1560ce30658b22ce104"
562
  },
 
 
 
 
 
 
 
 
 
 
 
 
563
  "munsell": {
564
  "Package": "munsell",
565
  "Version": "0.5.0",
@@ -739,6 +843,30 @@
739
  ],
740
  "Hash": "dc079ccd156cde8647360f473c1fa718"
741
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
742
  "rsconnect": {
743
  "Package": "rsconnect",
744
  "Version": "0.8.29",
@@ -830,6 +958,19 @@
830
  ],
831
  "Hash": "c2eae3d8c670fa9dfa35a12066f4a1d5"
832
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
833
  "sourcetools": {
834
  "Package": "sourcetools",
835
  "Version": "0.1.7-1",
@@ -840,6 +981,36 @@
840
  ],
841
  "Hash": "5f5a7629f956619d519205ec475fe647"
842
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
843
  "sys": {
844
  "Package": "sys",
845
  "Version": "3.4.1",
@@ -882,6 +1053,16 @@
882
  ],
883
  "Hash": "79540e5fcd9e0435af547d885f184fd5"
884
  },
 
 
 
 
 
 
 
 
 
 
885
  "tzdb": {
886
  "Package": "tzdb",
887
  "Version": "0.3.0",
@@ -966,6 +1147,17 @@
966
  ],
967
  "Hash": "c0e49a9760983e81e55cdd9be92e7182"
968
  },
 
 
 
 
 
 
 
 
 
 
 
969
  "xtable": {
970
  "Package": "xtable",
971
  "Version": "1.8-4",
 
187
  ],
188
  "Hash": "f20c47fd52fae58b4e377c37bb8c335b"
189
  },
190
+ "colourpicker": {
191
+ "Package": "colourpicker",
192
+ "Version": "1.2.0",
193
+ "Source": "Repository",
194
+ "Repository": "CRAN",
195
+ "Requirements": [
196
+ "R",
197
+ "ggplot2",
198
+ "htmltools",
199
+ "htmlwidgets",
200
+ "jsonlite",
201
+ "miniUI",
202
+ "shiny",
203
+ "shinyjs",
204
+ "utils"
205
+ ],
206
+ "Hash": "ca4d99d106687d68392ffe270081bfc0"
207
+ },
208
  "commonmark": {
209
  "Package": "commonmark",
210
  "Version": "1.9.0",
 
292
  ],
293
  "Hash": "bb0eec2fe32e88d9e2836c2f73ea2077"
294
  },
295
+ "evaluate": {
296
+ "Package": "evaluate",
297
+ "Version": "0.20",
298
+ "Source": "Repository",
299
+ "Repository": "CRAN",
300
+ "Requirements": [
301
+ "R",
302
+ "methods"
303
+ ],
304
+ "Hash": "4b68aa51edd89a0e044a66e75ae3cc6c"
305
+ },
306
  "fansi": {
307
  "Package": "fansi",
308
  "Version": "1.0.4",
 
363
  ],
364
  "Hash": "15e9634c0fcd294799e9b2e929ed1b86"
365
  },
366
+ "ggExtra": {
367
+ "Package": "ggExtra",
368
+ "Version": "0.10.0",
369
+ "Source": "Repository",
370
+ "Repository": "CRAN",
371
+ "Requirements": [
372
+ "R",
373
+ "R6",
374
+ "colourpicker",
375
+ "ggplot2",
376
+ "grDevices",
377
+ "grid",
378
+ "gtable",
379
+ "miniUI",
380
+ "scales",
381
+ "shiny",
382
+ "shinyjs",
383
+ "utils"
384
+ ],
385
+ "Hash": "f505d7f3058403787145fe0f7b1ff84c"
386
+ },
387
  "ggplot2": {
388
  "Package": "ggplot2",
389
  "Version": "3.4.2",
 
435
  ],
436
  "Hash": "b44addadb528a0d227794121c00572a0"
437
  },
438
+ "highr": {
439
+ "Package": "highr",
440
+ "Version": "0.10",
441
+ "Source": "Repository",
442
+ "Repository": "CRAN",
443
+ "Requirements": [
444
+ "R",
445
+ "xfun"
446
+ ],
447
+ "Hash": "06230136b2d2b9ba5805e1963fa6e890"
448
+ },
449
  "hms": {
450
  "Package": "hms",
451
  "Version": "1.1.3",
 
477
  ],
478
  "Hash": "ba0240784ad50a62165058a27459304a"
479
  },
480
+ "htmlwidgets": {
481
+ "Package": "htmlwidgets",
482
+ "Version": "1.6.2",
483
+ "Source": "Repository",
484
+ "Repository": "CRAN",
485
+ "Requirements": [
486
+ "grDevices",
487
+ "htmltools",
488
+ "jsonlite",
489
+ "knitr",
490
+ "rmarkdown",
491
+ "yaml"
492
+ ],
493
+ "Hash": "a865aa85bcb2697f47505bfd70422471"
494
+ },
495
  "httpuv": {
496
  "Package": "httpuv",
497
  "Version": "1.6.9",
 
538
  ],
539
  "Hash": "a4269a09a9b865579b2635c77e572374"
540
  },
541
+ "knitr": {
542
+ "Package": "knitr",
543
+ "Version": "1.42",
544
+ "Source": "Repository",
545
+ "Repository": "CRAN",
546
+ "Requirements": [
547
+ "R",
548
+ "evaluate",
549
+ "highr",
550
+ "methods",
551
+ "tools",
552
+ "xfun",
553
+ "yaml"
554
+ ],
555
+ "Hash": "8329a9bcc82943c8069104d4be3ee22d"
556
+ },
557
  "labeling": {
558
  "Package": "labeling",
559
  "Version": "0.4.2",
 
652
  ],
653
  "Hash": "18e9c28c1d3ca1560ce30658b22ce104"
654
  },
655
+ "miniUI": {
656
+ "Package": "miniUI",
657
+ "Version": "0.1.1.1",
658
+ "Source": "Repository",
659
+ "Repository": "CRAN",
660
+ "Requirements": [
661
+ "htmltools",
662
+ "shiny",
663
+ "utils"
664
+ ],
665
+ "Hash": "fec5f52652d60615fdb3957b3d74324a"
666
+ },
667
  "munsell": {
668
  "Package": "munsell",
669
  "Version": "0.5.0",
 
843
  ],
844
  "Hash": "dc079ccd156cde8647360f473c1fa718"
845
  },
846
+ "rmarkdown": {
847
+ "Package": "rmarkdown",
848
+ "Version": "2.21",
849
+ "Source": "Repository",
850
+ "Repository": "CRAN",
851
+ "Requirements": [
852
+ "R",
853
+ "bslib",
854
+ "evaluate",
855
+ "fontawesome",
856
+ "htmltools",
857
+ "jquerylib",
858
+ "jsonlite",
859
+ "knitr",
860
+ "methods",
861
+ "stringr",
862
+ "tinytex",
863
+ "tools",
864
+ "utils",
865
+ "xfun",
866
+ "yaml"
867
+ ],
868
+ "Hash": "493df4ae51e2e984952ea4d5c75786a3"
869
+ },
870
  "rsconnect": {
871
  "Package": "rsconnect",
872
  "Version": "0.8.29",
 
958
  ],
959
  "Hash": "c2eae3d8c670fa9dfa35a12066f4a1d5"
960
  },
961
+ "shinyjs": {
962
+ "Package": "shinyjs",
963
+ "Version": "2.1.0",
964
+ "Source": "Repository",
965
+ "Repository": "CRAN",
966
+ "Requirements": [
967
+ "R",
968
+ "digest",
969
+ "jsonlite",
970
+ "shiny"
971
+ ],
972
+ "Hash": "802e4786b353a4bb27116957558548d5"
973
+ },
974
  "sourcetools": {
975
  "Package": "sourcetools",
976
  "Version": "0.1.7-1",
 
981
  ],
982
  "Hash": "5f5a7629f956619d519205ec475fe647"
983
  },
984
+ "stringi": {
985
+ "Package": "stringi",
986
+ "Version": "1.7.12",
987
+ "Source": "Repository",
988
+ "Repository": "CRAN",
989
+ "Requirements": [
990
+ "R",
991
+ "stats",
992
+ "tools",
993
+ "utils"
994
+ ],
995
+ "Hash": "ca8bd84263c77310739d2cf64d84d7c9"
996
+ },
997
+ "stringr": {
998
+ "Package": "stringr",
999
+ "Version": "1.5.0",
1000
+ "Source": "Repository",
1001
+ "Repository": "CRAN",
1002
+ "Requirements": [
1003
+ "R",
1004
+ "cli",
1005
+ "glue",
1006
+ "lifecycle",
1007
+ "magrittr",
1008
+ "rlang",
1009
+ "stringi",
1010
+ "vctrs"
1011
+ ],
1012
+ "Hash": "671a4d384ae9d32fc47a14e98bfa3dc8"
1013
+ },
1014
  "sys": {
1015
  "Package": "sys",
1016
  "Version": "3.4.1",
 
1053
  ],
1054
  "Hash": "79540e5fcd9e0435af547d885f184fd5"
1055
  },
1056
+ "tinytex": {
1057
+ "Package": "tinytex",
1058
+ "Version": "0.45",
1059
+ "Source": "Repository",
1060
+ "Repository": "CRAN",
1061
+ "Requirements": [
1062
+ "xfun"
1063
+ ],
1064
+ "Hash": "e4e357f28c2edff493936b6cb30c3d65"
1065
+ },
1066
  "tzdb": {
1067
  "Package": "tzdb",
1068
  "Version": "0.3.0",
 
1147
  ],
1148
  "Hash": "c0e49a9760983e81e55cdd9be92e7182"
1149
  },
1150
+ "xfun": {
1151
+ "Package": "xfun",
1152
+ "Version": "0.38",
1153
+ "Source": "Repository",
1154
+ "Repository": "CRAN",
1155
+ "Requirements": [
1156
+ "stats",
1157
+ "tools"
1158
+ ],
1159
+ "Hash": "1ed71215d45e85562d3b1b29a068ccec"
1160
+ },
1161
  "xtable": {
1162
  "Package": "xtable",
1163
  "Version": "1.8-4",
examples.Rproj → simplepenguins.Rproj RENAMED
File without changes