[
  {
    "path": ".Rbuildignore",
    "content": "^.*\\.Rproj$\n^\\.Rproj\\.user$\n^README\\.Rmd$\n^README-.*\\.png$\n^\\.travis\\.yml$\n^cran-comments.md$\n^NEWS.md$\n"
  },
  {
    "path": ".gitignore",
    "content": ".Rproj.user/**\n.Rproj\n.Rhistory\n.RData\n.Ruserdata\n.Rproj.user\n.DS_Store\n"
  },
  {
    "path": ".travis.yml",
    "content": "# R for travis: see documentation at https://docs.travis-ci.com/user/languages/r\n\nlanguage: R\nsudo: false\ncache: packages\n"
  },
  {
    "path": "DESCRIPTION",
    "content": "Package: ggplotgui\nTitle: Create Ggplots via a Graphical User Interface\nVersion: 1.0.1\nAuthors@R: person(\"Gert\", \"Stulp\", email = \"g.stulp@rug.nl\", role = c(\"aut\", \"cre\"))\nDescription: Easily explore data by creating ggplots through a (shiny-)GUI. R-code to recreate graph provided.   \nDepends: R (>= 3.4)\nImports:\n    plotly,\n    shiny,\n    ggplot2,\n    stringr,\n    readr,\n    haven,\n    DT,\n    readxl,\n    RColorBrewer\nLicense: GPL-3\nBugReports: https://github.com/gertstulp/ggplotgui/issues\nURL: https://github.com/gertstulp/ggplotgui/\nEncoding: UTF-8\nLazyData: true\nRoxygenNote: 7.1.0\n"
  },
  {
    "path": "NAMESPACE",
    "content": "# Generated by roxygen2: do not edit by hand\n\nexport(ggplot_shiny)\nimport(RColorBrewer)\nimport(ggplot2)\nimport(haven)\nimport(readxl)\nimport(shiny)\nimportFrom(DT,DTOutput)\nimportFrom(DT,renderDT)\nimportFrom(plotly,ggplotly)\nimportFrom(plotly,plotlyOutput)\nimportFrom(plotly,renderPlotly)\nimportFrom(readr,locale)\nimportFrom(readr,read_delim)\nimportFrom(stringr,str_replace_all)\n"
  },
  {
    "path": "NEWS.md",
    "content": "## ggplotgui 1.0.1\n* fixed running error due to changes in Shiny's use of DT\n* fixed data import for different extensions\n* included option to choose delimiter\n\n"
  },
  {
    "path": "R/ggplot_shiny.R",
    "content": "#' Creating a graphical user interface for creating ggplot-graphs.\n#'\n#' @param dataset A dataset (optional).\n#' @return A GUI for visualizing data from \\code{dataset}.\n#' @examples\n#' #ggplot_shiny()\n#' #ggplot_shiny(mpg)\n#' @import ggplot2\n#' @import shiny\n#' @import readxl\n#' @import haven\n#' @import RColorBrewer\n#' @importFrom plotly ggplotly plotlyOutput renderPlotly\n#' @importFrom stringr str_replace_all\n#' @importFrom readr read_delim locale\n#' @importFrom DT renderDT DTOutput\n\n\n#' @export\nggplot_shiny <- function( dataset = NA ) {\n\n  ui <- fluidPage(\n    headerPanel(\"ggplot GUI\"),\n    sidebarPanel(width = 3,\n      conditionalPanel(\n        condition = \"input.tabs=='Data upload'\",\n        h4(\"Data upload\"),\n        radioButtons(\n          \"data_input\", \"\",\n          choices = if (is.data.frame(dataset)) {\n            list(\"Load sample data\" = 1,\n                 \"Upload text file\" = 2,\n                 \"Paste data\" = 3,\n                 \"Data passed through R environment\" = 4)\n              } else {\n              list(\"Load sample data\" = 1,\n                   \"Upload file\" = 2,\n                   \"Paste data\" = 3)\n              },\n          selected = if (is.data.frame(dataset)) 4 else 1),\n        conditionalPanel(\n          condition = \"input.data_input=='1'\",\n          h5(\"dataset 'mpg' from library(ggplot2) loaded\")\n          ),\n        conditionalPanel(\n          condition = \"input.data_input=='2'\",\n          h5(\"Upload file: \"),\n          fileInput(\"upload\", \"\", multiple = FALSE),\n          selectInput(\"file_type\", \"Type of file:\",\n                      list(\"text (csv)\" = \"text\",\n                           \"Excel\" = \"Excel\",\n                           \"SPSS\" = \"SPSS\",\n                           \"Stata\" = \"Stata\",\n                           \"SAS\" = \"SAS\"),\n                      selected = \"text\"),\n          conditionalPanel(\n            condition = \"input.file_type=='text'\",\n            selectInput(\"upload_delim\", \"Delimiter:\",\n                        list(\"Semicolon\" = \";\",\n                             \"Tab\" = \"\\t\",\n                             \"Comma\" = \",\",\n                             \"Space\" = \" \"),\n                        selected = \"Semicolon\"),\n            selectInput(\"upload_dec\", \"Decimal mark:\",\n                        list(\"Comma\" = \",\",\n                             \"Point\" = \".\"),\n                        selected = \"Comma\")\n          ),\n          actionButton(\"submit_datafile_button\",\n                       \"Submit datafile\")\n          ),\n        conditionalPanel(\n          condition = \"input.data_input=='3'\",\n          h5(\"Paste data below:\"),\n          tags$textarea(id = \"data_paste\",\n                        placeholder = \"Add data here\",\n                        rows = 10,\n                        cols = 20, \"\"),\n          actionButton(\"submit_data_button\", \"Submit data\"),\n          selectInput(\"text_delim\", \"Delimiter:\",\n                      list(\"Semicolon\" = \";\",\n                           \"Tab\" = \"\\t\",\n                           \"Comma\" = \",\",\n                           \"Space\" = \" \"),\n                      selected = \"Semicolon\"),\n          selectInput(\"text_dec\", \"Decimal mark:\",\n                      list(\"Comma\" = \",\",\n                           \"Point\" = \".\"),\n                      selected = \"Comma\")\n        )\n      ),\n      conditionalPanel(\n        condition = \"input.tabs=='ggplot' || input.tabs=='Plotly' ||\n                    input.tabs=='R-code'\",\n        h4(\"Create visualization\"),\n        selectInput(inputId = \"Type\",\n                    label = \"Type of graph:\",\n                    choices = c(\"Boxplot\", \"Density\", \"Dot + Error\",\n                                \"Dotplot\", \"Histogram\", \"Scatter\", \"Violin\"),\n                    selected = \"Violin\"),\n        selectInput(\"y_var\", \"Y-variable\", choices = \"\"),\n        conditionalPanel(\n          condition = \"input.Type!='Density' && input.Type!='Histogram'\",\n          selectInput(\"x_var\", \"X-variable\", choices = \"\")\n        ),\n        selectInput(\"group\", \"Group (or colour)\", choices = \"\"),\n        selectInput(\"facet_row\", \"Facet Row\", choices = \"\"),\n        selectInput(\"facet_col\", \"Facet Column\", choices = \"\"),\n        conditionalPanel(\n          condition = \"input.Type == 'Boxplot' || input.Type == 'Violin' ||\n          input.Type == 'Dot + Error'\",\n          checkboxInput(inputId = \"jitter\",\n                        label = strong(\"Show data points (jittered)\"),\n                        value = FALSE)\n        ),\n        conditionalPanel(\n          condition = \"input.Type == 'Boxplot'\",\n          checkboxInput(inputId = \"notch\",\n                        label = strong(\"Notched box plot\"),\n                        value = FALSE)\n        ),\n        conditionalPanel(\n          condition = \"input.Type == 'Density' || input.Type == 'Histogram'\",\n          sliderInput(\"alpha\", \"Opacity:\", min = 0, max = 1, value = 0.8)\n        ),\n        conditionalPanel(\n          condition = \"input.Type == 'Histogram' || input.Type=='Dotplot'\",\n          numericInput(\"binwidth\", \"Binwidth:\", value = 1)\n        ),\n        conditionalPanel(\n          condition = \"input.Type == 'Dotplot'\",\n          selectInput(\"dot_dir\", \"Direction stack:\",\n                      choices = c(\"up\", \"down\", \"center\", \"centerwhole\"),\n                      selected = \"up\")\n        ),\n        conditionalPanel(\n          condition = \"input.Type == 'Density' || input.Type == 'Violin'\",\n          sliderInput(inputId = \"adj_bw\",\n                      label = \"Bandwidth adjustment:\",\n                      min = 0.01, max = 2, value = 1, step = 0.1)\n        ),\n        conditionalPanel(\n          condition = \"input.Type == 'Scatter'\",\n          checkboxInput(inputId = \"line\",\n                        label = strong(\"Show regression line\"),\n                        value = FALSE),\n          conditionalPanel(\n            condition = \"input.line == true\",\n            selectInput(\"smooth\", \"Smoothening function\",\n                        choices = c(\"lm\", \"loess\", \"gam\"))\n          ),\n          conditionalPanel(\n            condition = \"input.line == true\",\n            checkboxInput(inputId = \"se\",\n                          label = strong(\"Show confidence interval\"),\n                          value = FALSE)\n          )\n        ),\n        conditionalPanel(\n          condition = \"input.Type == 'Dot + Error'\",\n          selectInput(\"CI\", \"Confidence Interval:\",\n                      choices = c(\"68% (1 SE)\" = 1,\n                                  \"90%\" = 1.645,\n                                  \"95%\" = 1.96,\n                                  \"99%\" = 2.575),\n                      selected = 1.96)\n        )\n      ),\n      conditionalPanel(\n        condition = \"input.tabs=='Info'\",\n        h4(\"Info\")\n      )\n    ),\n    h6(\"For more info see the 'Info'-tab or visit\",\n       a(\"https://github.com/gertstulp/ggplotgui\",\n         href = \"https://github.com/gertstulp/ggplotgui\")),\n\n#####################################\n########### OUPUT TABS ##############\n#####################################\n\n    mainPanel(width = 6,\n      tabsetPanel(\n        type = \"tabs\",\n        tabPanel(\"Data upload\", DT::DTOutput(\"out_table\")),\n        tabPanel(\"ggplot\",\n                 mainPanel(\n                   downloadButton(\"download_plot_PDF\",\n                                  \"Download pdf of figure\"),\n                   plotOutput(\"out_ggplot\"))\n                ),\n        tabPanel(\"Plotly\", plotlyOutput(\"out_plotly\")),\n        tabPanel(\"R-code\", verbatimTextOutput(\"out_r_code\")),\n        tabPanel(\"Info\",\nh3(\"Background\"),\np(\n  a(\"R\", href = \"https://www.r-project.org/\"), \"is amazing, but daunting\n  for many. The programming style of R, compared to the point-and-click\n  style of typical software, is a hurdle for many. Perhaps particularly so\n  for those in the social sciences, whose statistical needs are often met by\n  other software packages. Yet such packages are often very limited in terms\n  of their options to visualize the data at hand. I believe that the amazing\n  visualization-capabilities of R might be one way to get more people to use it.\n  To lower the barrier to start using R, this package allows users to visualize\n  their data using an online graphical user interface (GUI) that makes use of\n  R's visualization package\",\n  a(\"ggplot\", href = \"http://ggplot2.org/\"),\n  \". There are two ways of using this functionality: 1) online, where users\n  can upload their data and visualize it without needing R, by visiting \",\n  a(\"this website\",\n    href = \"https://site.shinyserver.dck.gmw.rug.nl/ggplotgui/\"),\n  \"; 2) from within the R-environment (by using the \", code(\"ggplot_shiny()\"),\n  \"function). Importantly, the R-code will also be provided such that the user\n  can recreate the graphs within the R-environment. The main aim (or hope) is\n  to get more people using R and its wonderful (graphing) capabilities.\"\n),\nh3(\"App info\"),\np(\n  \"This application was built in \",\n  a(\"R\", href = \"https://www.r-project.org/\"),\n  \"version 3.3.2, and uses the following packages: \",\n  a(\"ggplot2\", href = \"http://ggplot2.tidyverse.org/\"), \",\",\n  a(\"Shiny\", href = \"http://www.rstudio.com/shiny/\"), \",\",\n  a(\"stringr\", href = \"http://stringr.tidyverse.org/\"), \",\",\n  a(\"plotly\", href = \"https://plot.ly/r/\"), \",\",\n  a(\"readr\", href = \"http://readr.tidyverse.org/\"), \",\",\n  a(\"readxl\", href = \"http://readxl.tidyverse.org/\"), \",\",\n  a(\"haven\", href = \"http://haven.tidyverse.org/\"), \", and\",\n  a(\"RColorBrewer.\", href = \"http://stringr.tidyverse.org/\")\n),\np(\n  \"This application was created by \",\n  a(\"Gert Stulp\", href = \"http://www.gertstulp.com/\"),\n  \". Please do report bugs and send feature requests to \",\n  a(\"g.stulp[at]rug.nl\", href = \"mailto:g.stulp@rug.nl\"),\n  \". Visit \",\n  a(\"https://github.com/gertstulp/ggplotgui\",\n    href = \"https://github.com/gertstulp/ggplotgui\"),\n  \"for further description and code.\"\n),\nh3(\"Acknowledgements\"),\np(\n  \"Thanks to Wilmer Joling for setting up the \",\n  a(\"website\", href = \"https://site.shinyserver.dck.gmw.rug.nl/ggplotgui/\"),\n  \"which is based on the magical but incomprehensible\",\n  a(\"docker\", href = \"https://www.docker.com/\"),\n  \". Thanks to \",\n  a(\"Hadley Wickham\", href = \"http://hadley.nz/\"),\n  \" for making such good packages (and open access\n  books describing them), that allow even low-skilled\n  and low-talented programmers like myself to be able to\n  contribute to R\"\n)\n        ),\n        id = \"tabs\"\n      )\n    ),\n\n#####################################\n######### AESTHETICS TAB ############\n#####################################\n\n    conditionalPanel(\n      condition = \"input.tabs=='ggplot' || input.tabs=='Plotly' ||\n                    input.tabs=='R-code'\",\n      sidebarPanel(\n        width = 3,\n        h4(\"Change aesthetics\"),\n        tabsetPanel(\n          tabPanel(\n            \"Text\",\n            checkboxInput(inputId = \"label_axes\",\n                          label = strong(\"Change labels axes\"),\n                          value = FALSE),\n            conditionalPanel(\n              condition = \"input.label_axes == true\",\n              textInput(\"lab_x\", \"X-axis:\", value = \"label x-axis\")\n            ),\n            conditionalPanel(\n              condition = \"input.label_axes == true\",\n              textInput(\"lab_y\", \"Y-axis:\", value = \"label y-axis\")\n            ),\n            checkboxInput(inputId = \"add_title\",\n                          label = strong(\"Add title\"),\n                          value = FALSE),\n            conditionalPanel(\n              condition = \"input.add_title == true\",\n              textInput(\"title\", \"Title:\", value = \"Title\")\n            ),\n            checkboxInput(inputId = \"adj_fnt_sz\",\n                          label = strong(\"Change font size\"),\n                          value = FALSE),\n            conditionalPanel(\n              condition = \"input.adj_fnt_sz == true\",\n              numericInput(\"fnt_sz_ttl\",\n                           \"Size axis titles:\",\n                           value = 12),\n              numericInput(\"fnt_sz_ax\",\n                           \"Size axis labels:\",\n                           value = 10)\n            ),\n            checkboxInput(inputId = \"rot_txt\",\n                          label = strong(\"Rotate text x-axis\"),\n                          value = FALSE),\n            checkboxInput(inputId = \"adj_fnt\",\n                          label = strong(\"Change font\"),\n                          value = FALSE),\n            conditionalPanel(\n              condition = \"input.adj_fnt == true\",\n              selectInput(\"font\", \"Font\",\n                          choices = c(\"Courier\",\n                                      \"Helvetica\",\n                                      \"Times\"),\n                          selected = \"Helvetica\")\n            )\n          ),\n          tabPanel(\n            \"Theme\",\n            conditionalPanel(\n              condition = \"input.group != '.'\",\n              checkboxInput(inputId = \"adj_col\",\n                            label = strong(\"Change colours\"),\n                            value = FALSE),\n              conditionalPanel(\n                condition = \"input.adj_col\",\n                selectInput(inputId = \"palet\",\n                            label = strong(\"Select palette\"),\n                            choices = list(\n                              \"Qualitative\" = c(\"Accent\",\n                                                \"Dark2\",\n                                                \"Paired\",\n                                                \"Pastel1\",\n                                                \"Pastel2\",\n                                                \"Set1\",\n                                                \"Set2\",\n                                                \"Set3\"),\n                              \"Diverging\" = c(\"BrBG\",\n                                              \"PiYG\",\n                                              \"PRGn\",\n                                              \"PuOr\",\n                                              \"RdBu\",\n                                              \"RdGy\",\n                                              \"RdYlBu\",\n                                              \"RdYlGn\",\n                                              \"Spectral\"),\n                              \"Sequential\" = c(\"Blues\",\n                                               \"BuGn\",\n                                               \"BuPu\",\n                                               \"GnBu\",\n                                               \"Greens\",\n                                               \"Greys\",\n                                               \"Oranges\",\n                                               \"OrRd\",\n                                               \"PuBu\",\n                                               \"PuBuGn\",\n                                               \"PuRd\",\n                                               \"Purples\",\n                                               \"RdPu\",\n                                               \"Reds\",\n                                               \"YlGn\",\n                                               \"YlGnBu\",\n                                               \"YlOrBr\",\n                                               \"YlOrRd\")),\n                            selected = \"set1\")\n              )\n            ),\n            conditionalPanel(\n              condition = \"input.jitter\",\n              checkboxInput(\"adj_jitter\",\n                            strong(\"Change look jitter\"), FALSE),\n              conditionalPanel(\n                condition = \"input.adj_jitter\",\n                textInput(\"col_jitter\", \"Colour (name or RGB):\",\n                          value = \"black\"),\n                numericInput(\"size_jitter\", \"Size:\", value = 1),\n                sliderInput(\"opac_jitter\", \"Opacity:\",\n                            min = 0, max = 1, value = 0.5, step = 0.01),\n                sliderInput(\"width_jitter\", \"Width jitter:\",\n                            min = 0, max = 0.5, value = 0.25, step = 0.01)\n              )\n            ),\n            checkboxInput(\"adj_grd\",\n                          strong(\"Remove gridlines\"), FALSE),\n            conditionalPanel(\n              condition = \"input.adj_grd\",\n              checkboxInput(\"grd_maj\",\n                            strong(\"Remove major gridlines\"), FALSE),\n              checkboxInput(\"grd_min\",\n                            strong(\"Remove minor gridlines\"), FALSE)\n            ),\n            selectInput(\"theme\", \"Theme\",\n                        choices = c(\"bw\" = \"theme_bw()\",\n                                    \"classic\" = \"theme_classic()\",\n                                    \"dark\" = \"theme_dark()\",\n                                    \"grey\" = \"theme_grey()\",\n                                    \"light\" = \"theme_light()\",\n                                    \"line_draw\" = \"theme_linedraw()\",\n                                    \"minimal\" = \"theme_minimal()\"),\n                        selected = \"theme_bw()\")\n          ),\n          tabPanel(\n            \"Legend\",\n            conditionalPanel(\n              condition = \"input.group != '.'\",\n              radioButtons(inputId = \"adj_leg\",\n                           label = NULL,\n                           choices = c(\"Keep legend as it is\",\n                                       \"Remove legend\",\n                                       \"Change legend\"),\n                           selected = \"Keep legend as it is\"),\n              conditionalPanel(\n                condition = \"input.adj_leg=='Change legend'\",\n                textInput(\"leg_ttl\", \"Title legend:\",\n                          value = \"title legend\"),\n                selectInput(\"pos_leg\", \"Position legend\",\n                            choices = c(\"right\",\n                                        \"left\",\n                                        \"top\",\n                                        \"bottom\"))\n              )\n            )\n          ),\n          tabPanel(\n            \"Size\",\n            checkboxInput(\"fig_size\",\n                          strong(\"Adjust plot size on screen\"), FALSE),\n            conditionalPanel(\n              condition = \"input.fig_size\",\n              numericInput(\"fig_height\", \"Plot height (# pixels): \",\n                           value = 480),\n              numericInput(\"fig_width\", \"Plot width (# pixels):\", value = 480)\n            ),\n            checkboxInput(\"fig_size_download\",\n                          strong(\"Adjust plot size for download\"), FALSE),\n            conditionalPanel(\n              condition = \"input.fig_size_download\",\n              numericInput(\"fig_height_download\",\n                           \"Plot height (in cm):\", value = 14),\n              numericInput(\"fig_width_download\",\n                           \"Plot width (in cm):\", value = 14)\n            )\n          )\n        ) # Close tabsetPanel\n      ) # Close sidebarPanel\n    ) # Close conditionalPanel\n  ) # Close fluidPage\n\n  server <- function(input, output, session) {\n\n#####################################\n### GET VARIABLE NAMES FOR INPUT ####\n#####################################\n\n    observe({\n      nms <- names(df_shiny())\n      # Make list of variables that are not factors\n      nms_cont <- names(Filter(function(x) is.integer(x) ||\n                                 is.numeric(x) ||\n                                 is.double(x),\n                               df_shiny()))\n\n      # Make list of variables that are factors\n      nms_fact <- names(Filter(function(x) is.factor(x) ||\n                                 is.logical(x) ||\n                                 is.character(x),\n                               df_shiny()))\n\n      avail_all <- c(\"No groups\" = \".\", nms)\n      avail_con <-\n        if (identical(nms_cont, character(0)))\n          c(\"No continuous vars available\" = \".\")\n        else c(nms_cont)\n      avail_fac <-\n        if (identical(nms_fact, character(0)))\n          c(\"No factors available\" = \".\")\n        else c(\"No groups\" = \".\", nms_fact)\n\n      updateSelectInput(session, \"y_var\", choices = avail_con)\n      updateSelectInput(session, \"x_var\", choices = c(\"No x-var\" = \"' '\", nms))\n      updateSelectInput(session, \"group\", choices = avail_all)\n      updateSelectInput(session, \"facet_row\",  choices = avail_fac)\n      updateSelectInput(session, \"facet_col\",  choices = avail_fac)\n    })\n\n\n#####################################\n###### READ IN / GET DATA ###########\n#####################################\n\n    df_shiny <- reactive({\n      if (input$data_input == 1) {\n        data <- ggplot2::mpg\n      } else if (input$data_input == 2) {\n        file_in <- input$upload\n        # Avoid error message while file is not uploaded yet\n        if (is.null(input$upload)) {\n          return(data.frame(x = \"Select your datafile\"))\n        } else if (input$submit_datafile_button == 0) {\n          return(data.frame(x = \"Press 'submit datafile' button\"))\n        } else {\n          isolate({\n            if (input$file_type == \"text\") {\n              data <- read_delim(file_in$datapath,\n                                 delim = input$upload_delim,\n                                 locale = locale(decimal_mark = input$upload_dec),\n                                 col_names = TRUE)\n            } else if (input$file_type == \"Excel\") {\n              data <- read_excel(file_in$datapath)\n            } else if (input$file_type == \"SPSS\") {\n              data <- read_sav(file_in$datapath)\n            } else if (input$file_type == \"Stata\") {\n              data <- read_dta(file_in$datapath)\n            } else if (input$file_type == \"SAS\") {\n              data <- read_sas(file_in$datapath)\n            }\n          })\n        }\n      } else if (input$data_input == 3) {\n        if (input$data_paste == \"\") {\n          data <- data.frame(x = \"Copy your data into the textbox,\n                             select the appropriate delimiter, and\n                             press 'Submit data'\")\n        } else {\n          if (input$submit_data_button == 0) {\n            return(data.frame(x = \"Press 'submit data' button\"))\n          } else {\n            isolate({\n              data <- read_delim(input$data_paste,\n                                 delim = input$text_delim,\n                                 locale = locale(decimal_mark = input$text_dec),\n                                 col_names = TRUE)\n            })\n          }\n        }\n      } else if (input$data_input == 4){\n        data <- dataset\n      }\n      return(data)\n    })\n\n#####################################\n####### CREATE GRAPH-CODE ###########\n#####################################\n\n    string_code <- reactive({\n\n      # Variable used for how to deal with x/y in ggplot\n      gg_x_y <- input$Type == \"Histogram\" ||\n                input$Type == \"Density\"\n      # Variable used for how to deal with colour/fill\n      gg_fil <- input$Type == \"Histogram\" ||\n                input$Type == \"Density\" ||\n                input$Type == \"Dotplot\"\n\n      # Only plot jitter when graphs allow them\n      if (gg_fil || input$Type == \"Scatter\")\n        jitt <- FALSE else jitt <- input$jitter\n\n      p <- paste(\n        \"ggplot(df, aes(\",\n        if (gg_x_y) {\n          \"x = input$y_var\"\n        } else {\n          \"x = input$x_var, y = input$y_var\"\n        },\n        if (input$group != \".\" && gg_fil) {\n          \", fill = input$group\"\n        } else if (input$group != \".\" && !gg_fil) {\n          \", colour = input$group\"\n        },\n        \")) + \",\n        if (input$Type == \"Histogram\")\n          paste(\"geom_histogram(position = 'identity', alpha = input$alpha, \",\n                \"binwidth = input$binwidth)\", sep = \"\"),\n        if (input$Type == \"Density\")\n          paste(\"geom_density(position = 'identity', alpha = input$alpha, \",\n                \"adjust = input$adj_bw)\", sep = \"\"),\n        if (input$Type == \"Boxplot\")\n          \"geom_boxplot(notch = input$notch)\",\n        if (input$Type == \"Violin\")\n          \"geom_violin(adjust = input$adj_bw)\",\n        if (input$Type == \"Dotplot\")\n          paste(\"geom_dotplot(binaxis = 'y', binwidth = input$binwidth, \",\n                \"stackdir = 'input$dot_dir')\", sep = \"\"),\n        if (input$Type == \"Dot + Error\")\n          paste(\"geom_point(stat = 'summary', fun = 'mean') +\\n  \",\n                \"geom_errorbar(stat = 'summary', fun.data = 'mean_se', \", \"\n                width=0, fun.args = list(mult = input$CI))\", sep = \"\"),\n        if (input$Type == \"Scatter\")\n          \"geom_point()\",\n        if (input$Type == \"Scatter\" && input$line)\n          \"+ geom_smooth(se = input$se, method = 'input$smooth')\",\n        if (jitt)\n          paste(\" + geom_jitter(size = input$size_jitter, \",\n                \"alpha = input$opac_jitter, width = input$width_jitter, \",\n                \"colour = 'input$col_jitter')\", sep = \"\"),\n        sep = \"\"\n      )\n\n      # if at least one facet column/row is specified, add it\n      facets <- paste(input$facet_row, \"~\", input$facet_col)\n      if (facets != \". ~ .\")\n        p <- paste(p, \"+ facet_grid(\", facets, \")\")\n\n      # if labels specified\n      if (input$label_axes)\n        p <- paste(p, \"+ labs(x = 'input$lab_x', y = 'input$lab_y')\")\n\n      # if title specified\n      if (input$add_title)\n        p <- paste(p, \"+ ggtitle('input$title')\")\n\n      # if legend specified\n      if (input$adj_leg == \"Change legend\")\n        p <- paste(p, \"+ labs(\",\n                   if (gg_fil) \"fill\" else \"colour\",\n                   \" = 'input$leg_ttl')\",\n                   sep = \"\")\n\n      # if colour legend specified\n      if (input$adj_col)\n        p <- paste(p, \"+ scale_\",\n                   if (gg_fil) \"fill\" else \"colour\",\n                   \"_brewer(palette = 'input$palet')\",\n                   sep = \"\")\n\n      # If a theme specified\n      p <- paste(p, \"+\", input$theme)\n\n      # If theme features are specified\n      if (input$adj_fnt_sz ||\n          input$adj_fnt ||\n          input$rot_txt ||\n          input$adj_leg != \"Keep legend as it is\" ||\n          input$adj_grd) {\n        p <- paste(\n          p,\n          paste(\n            \" + theme(\\n    \",\n            if (input$adj_fnt_sz)\n\"axis.title = element_text(size = input$fnt_sz_ttl),\\n    \",\n            if (input$adj_fnt_sz)\n\"axis.text = element_text(size = input$fnt_sz_ax),\\n    \",\n            if (input$adj_fnt)\n\"text = element_text(family = 'input$font'),\\n    \",\n            if (input$rot_txt)\n\"axis.text.x = element_text(angle = 45, hjust = 1),\\n    \",\n            if (input$adj_leg == \"Remove legend\")\n\"legend.position = 'none',\\n    \",\n            if (input$adj_leg == \"Change legend\")\n\"legend.position = 'input$pos_leg',\\n    \",\n            if (input$grd_maj)\n\"panel.grid.major = element_blank(),\\n    \",\n            if (input$grd_min)\n\"panel.grid.minor = element_blank(),\\n    \",\n\")\",\n            sep = \"\"\n          ),\n          sep = \"\"\n        )\n      }\n\n      # Replace name of variables by values\n      p <- str_replace_all(\n             p,\n             c(\"input\\\\$y_var\" = input$y_var,\n               \"input\\\\$x_var\" = input$x_var,\n               \"input\\\\$group\" = input$group,\n               \"input\\\\$notch\" = as.character(input$notch),\n               \"input\\\\$binwidth\" = as.character(input$binwidth),\n               \"input\\\\$adj_bw\" = as.character(input$adj_bw),\n               \"input\\\\$dot_dir\" = as.character(input$dot_dir),\n               \"input\\\\$alpha\" = as.character(input$alpha),\n               \"input\\\\$se\" = as.character(input$se),\n               \"input\\\\$smooth\" = as.character(input$smooth),\n               \"input\\\\$CI\" = as.character(input$CI),\n               \"input\\\\$size_jitter\" = as.character(input$size_jitter),\n               \"input\\\\$width_jitter\" = as.character(input$width_jitter),\n               \"input\\\\$opac_jitter\" = as.character(input$opac_jitter),\n               \"input\\\\$col_jitter\" = as.character(input$col_jitter),\n               \"input\\\\$lab_x\" = as.character(input$lab_x),\n               \"input\\\\$lab_y\" = as.character(input$lab_y),\n               \"input\\\\$title\" = as.character(input$title),\n               \"input\\\\$palet\" = as.character(input$palet),\n               \"input\\\\$fnt_sz_ttl\" = as.character(input$fnt_sz_ttl),\n               \"input\\\\$fnt_sz_ax\" = as.character(input$fnt_sz_ax),\n               \"input\\\\$font\" = as.character(input$font),\n               \"input\\\\$leg_ttl\" = as.character(input$leg_ttl),\n               \"input\\\\$pos_leg\" = as.character(input$pos_leg))\n      )\n      # Creates well-formatted R-code for output\n      p <- str_replace_all(p, \",\\n    \\\\)\", \"\\n  \\\\)\")\n\n      p\n    })\n\n\n#####################################\n###### GRAPHICAL/TABLE OUTPUT #######\n#####################################\n\n    output$out_table <- DT::renderDT(\n      df_shiny()\n    )\n\n    width <- reactive ({ input$fig_width })\n    height <- reactive ({ input$fig_height })\n    width_download <- reactive ({ input$fig_width_download })\n    height_download <- reactive ({ input$fig_height_download })\n\n    output$out_ggplot <- renderPlot(width = width,\n                                    height = height, {\n      # evaluate the string RCode as code\n      df <- df_shiny()\n      p <- eval(parse(text = string_code()))\n      p\n    })\n\n    output$out_plotly <- renderPlotly({\n      # evaluate the string RCode as code\n      df <- df_shiny()\n      p <- eval(parse(text = string_code()))\n      ggplotly(p)\n    })\n\n#####################################\n#### GENERATE R-CODE FOR OUTPUT #####\n#####################################\n\n    output$out_r_code <- renderText({\n\n      gg_code <- string_code()\n      gg_code <- str_replace_all(gg_code, \"\\\\+ \", \"+\\n  \")\n\n      paste(\n        \"## You can use the below code to generate the graph.\\n\",\n        \"## Don't forget to replace the 'df' with the name\\n\",\n        \"## of your dataframe\\n\\n\",\n        \"# You need the following package(s):\\n\",\n        \"library(\\\"ggplot2\\\")\\n\\n\",\n        \"# The code below will generate the graph:\\n\",\n        \"graph <- \",\n        gg_code,\n        \"\\ngraph\\n\\n\",\n        \"# If you want the plot to be interactive,\\n\",\n        \"# you need the following package(s):\\n\",\n        \"library(\\\"plotly\\\")\\n\",\n        \"ggplotly(graph)\\n\\n\",\n        \"# If you would like to save your graph, you can use:\\n\",\n        \"ggsave('my_graph.pdf', graph, width = \",\n        width_download(),\n        \", height = \",\n        height_download(),\n        \", units = 'cm')\",\n        sep = \"\"\n      )\n\n    })\n\n#####################################\n#### GENERATE R-CODE FOR OUTPUT #####\n#####################################\n\n  output$download_plot_PDF <- downloadHandler(\n      filename <- function() {\n        paste(\"Figure_ggplotGUI_\", Sys.time(), \".pdf\", sep = \"\")\n      },\n      content <- function(file) {\n        df <- df_shiny()\n        p <- eval(parse(text = string_code()))\n        ggsave(file, p, width = width_download(),\n               height = height_download(), units = \"cm\")\n      },\n      contentType = \"application/pdf\" # MIME type of the image\n  )\n\n    # End R-session when browser closed\n    session$onSessionEnded(stopApp)\n  }\n  shinyApp(ui, server)\n}\n"
  },
  {
    "path": "README.Rmd",
    "content": "---\noutput: github_document\n---\n\n<!-- README.md is generated from README.Rmd. Please edit that file -->\n\n```{r, echo = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#>\",\n  fig.path = \"README-\"\n)\n```\n\nggplotgui\n==========\n[![Travis-CI Build Status](https://travis-ci.org/gertstulp/ggplotgui.svg?branch=master)](https://travis-ci.org/gertstulp/ggplotgui)\n[![CRAN\\_Release\\_Badge](http://www.r-pkg.org/badges/version-ago/ggplotgui)](https://CRAN.R-project.org/package=ggplotgui) [![CRAN\\_Download\\_Badge](http://cranlogs.r-pkg.org/badges/ggplotgui)](https://CRAN.R-project.org/package=ggplotgui)\n\n# Quick overview\nThis package allows users to visualize their data using an online graphical user interface (GUI) that makes use of [R](https://www.r-project.org/)'s visualization package [ggplot](http://ggplot2.org/). There are two ways of using this functionality: 1) online, where users can upload their data and visualize it without needing R, by visiting this link: https://site.shinyserver.dck.gmw.rug.nl/ggplotgui/; 2) from within the R-environment (by using the `ggplot_shiny()` function). In either case, R-code will be provided such that the user can recreate the graphs within the R-environment.  \n\n# Background\n[R](https://www.r-project.org/) is amazing, but daunting for many. The programming style of R, compared to the point-and-click style of typical software, is a hurdle for many. Perhaps particularly so for those in the social sciences, whose statistical needs are often met by other software packages. Yet such packages are often very limited in terms of their options to visualize the data at hand. I believe that the amazing visualization-capabilities of R might be one way to get more people to use it. To lower the barrier to start using R, this package allows users to visualize their data using an online graphical user interface (GUI) that makes use of R's visualization package [ggplot](http://ggplot2.org/). There are two ways of using this functionality: 1) online, where users can upload their data and visualize it without needing R, by visiting this link: https://site.shinyserver.dck.gmw.rug.nl/ggplotgui/; 2) from within the R-environment (by using the ggplot_shiny() function). Importantly, the R-code will also be provided such that the user can recreate the graphs within the R-environment. The main aim (or hope) is to get more people using R and its wonderful (graphing) capabilities.  \n\n# Installation\n```{r, eval=FALSE}\ninstall.packages(\"ggplotgui\")\n\n# In order to install the most recent version of this package, you'll need to use the \"devtools\"-package\ninstall.packages(\"devtools\")\ndevtools::install_github(\"gertstulp/ggplotgui\")\n\nlibrary(\"ggplotgui\")\n```\n\n# Usage\nThere are two ways to use this functionality:\n\n* By calling it from within R\n```{r, eval=FALSE}\n# You can call the function with and without passing a dataset\nggplot_shiny()\nggplot_shiny(mpg) # Passing ggplot's mpg dataset\n```\n* By using the following link:\nhttps://site.shinyserver.dck.gmw.rug.nl/ggplotgui/\n\nThis will open up the following screen:\n![](man/figures/tab_data_upload.png)\nThere are four ways in which you can use data within this GUI:    \n1. You can pass your dataframe through R, by using ggplot_gui(my_df)    \n2. You can examine sample data (data 'mpg' from the ggplot2 package)    \n3. You can upload your datafile in many different formats (e.g., csv, SPSS, Excel)    \n4. You can paste some data into a window (the data need to be \"[tidy](http://tidyr.tidyverse.org/)\")    \n\n\nA ggplot-graph can be made through point and click (after data is loaded and through the ggplot-tab):\n![](man/figures/tab_ggplot.png)\nAesthetics of the graph can be changed with the tabs on the right hand side. \n\nAn interactive version (through plotly) of the graph is displayed (the Plotly-tab) to allow for further exploration of the data:\n![](man/figures/tab_plotly.png)\n\n\nImportantly, the R-code to recreate the graphs will be provided (in the R-code tab):\n![](man/figures/tab_R-code.png)\n\n# Current functionality\nCurrently, only widely used graphs are implemented: boxplots, density plots, dot + error plots, dotplots, histograms, scatter plots, and violin plots. Only a select number of aesthetic features can be changed. Please do report bugs and send feature requests.\n\n# Acknowledgements\nI am grateful to the people who made [R](https://www.r-project.org/), and to [Hadley Wicham](http://hadley.nz/) for making such good packages (and open access books describing them), that allow even low-skilled and low-talented programmers like myself to be able to contribute to R. This package makes use of: [ggplot2](http://ggplot2.tidyverse.org/), [Shiny](http://shiny.rstudio.com/), [stringr](http://stringr.tidyverse.org/), [plotly](https://plot.ly/r/), [readr](http://readr.tidyverse.org/), [readxl](http://readxl.tidyverse.org/), [haven](http://haven.tidyverse.org/), and [RColorBrewer](https://cran.r-project.org/web/packages/RColorBrewer/RColorBrewer.pdf). Package development through [RStudio](https://www.rstudio.com/) and [Github](https://github.com/), and with the help of [R Markdown](http://rmarkdown.rstudio.com) and [devtools](https://www.rstudio.com/products/rpackages/devtools/). The code that allows for online data input was based somewhat on the [BoxPlotR Shiny app](https://github.com/VizWizard/BoxPlotR.shiny). Many thanks to Wilmer Joling who set up the illustrous \"[docker](https://www.docker.com/)\" and [website](https://site.shinyserver.dck.gmw.rug.nl/ggplotgui/) where the online version of this packages runs.   \n"
  },
  {
    "path": "README.md",
    "content": "\n<!-- README.md is generated from README.Rmd. Please edit that file -->\nggplotgui\n=========\n\n[![Travis-CI Build Status](https://travis-ci.org/gertstulp/ggplotgui.svg?branch=master)](https://travis-ci.org/gertstulp/ggplotgui) [![CRAN\\_Release\\_Badge](http://www.r-pkg.org/badges/version-ago/ggplotgui)](https://CRAN.R-project.org/package=ggplotgui) [![CRAN\\_Download\\_Badge](http://cranlogs.r-pkg.org/badges/ggplotgui)](https://CRAN.R-project.org/package=ggplotgui)\n\nQuick overview\n==============\n\nThis package allows users to visualize their data using an online graphical user interface (GUI) that makes use of [R](https://www.r-project.org/)'s visualization package [ggplot](http://ggplot2.org/). There are two ways of using this functionality: 1) online, where users can upload their data and visualize it without needing R, by visiting this link: <https://site.shinyserver.dck.gmw.rug.nl/ggplotgui/>; 2) from within the R-environment (by using the `ggplot_shiny()` function). In either case, R-code will be provided such that the user can recreate the graphs within the R-environment.\n\nBackground\n==========\n\n[R](https://www.r-project.org/) is amazing, but daunting for many. The programming style of R, compared to the point-and-click style of typical software, is a hurdle for many. Perhaps particularly so for those in the social sciences, whose statistical needs are often met by other software packages. Yet such packages are often very limited in terms of their options to visualize the data at hand. I believe that the amazing visualization-capabilities of R might be one way to get more people to use it. To lower the barrier to start using R, this package allows users to visualize their data using an online graphical user interface (GUI) that makes use of R's visualization package [ggplot](http://ggplot2.org/). There are two ways of using this functionality: 1) online, where users can upload their data and visualize it without needing R, by visiting this link: <https://site.shinyserver.dck.gmw.rug.nl/ggplotgui/>; 2) from within the R-environment (by using the ggplot\\_shiny() function). Importantly, the R-code will also be provided such that the user can recreate the graphs within the R-environment. The main aim (or hope) is to get more people using R and its wonderful (graphing) capabilities.\n\nInstallation\n============\n\n``` r\ninstall.packages(\"ggplotgui\")\n\n# In order to install the most recent version of this package, you'll need to use the \"devtools\"-package\ninstall.packages(\"devtools\")\ndevtools::install_github(\"gertstulp/ggplotgui\")\n\nlibrary(\"ggplotgui\")\n```\n\nUsage\n=====\n\nThere are two ways to use this functionality:\n\n-   By calling it from within R\n\n``` r\n# You can call the function with and without passing a dataset\nggplot_shiny()\nggplot_shiny(mpg) # Passing ggplot's mpg dataset\n```\n\n-   By using the following link: <https://site.shinyserver.dck.gmw.rug.nl/ggplotgui/>\n\nThis will open up the following screen: ![](man/figures/tab_data_upload.png) There are four ways in which you can use data within this GUI:\n1. You can pass your dataframe through R, by using ggplot\\_gui(my\\_df)\n2. You can examine sample data (data 'mpg' from the ggplot2 package)\n3. You can upload your datafile in many different formats (e.g., csv, SPSS, Excel)\n4. You can paste some data into a window (the data need to be \"[tidy](http://tidyr.tidyverse.org/)\")\n\nA ggplot-graph can be made through point and click (after data is loaded and through the ggplot-tab): ![](man/figures/tab_ggplot.png) Aesthetics of the graph can be changed with the tabs on the right hand side.\n\nAn interactive version (through plotly) of the graph is displayed (the Plotly-tab) to allow for further exploration of the data: ![](man/figures/tab_plotly.png)\n\nImportantly, the R-code to recreate the graphs will be provided (in the R-code tab): ![](man/figures/tab_R-code.png)\n\nCurrent functionality\n=====================\n\nCurrently, only widely used graphs are implemented: boxplots, density plots, dot + error plots, dotplots, histograms, scatter plots, and violin plots. Only a select number of aesthetic features can be changed. Please do report bugs and send feature requests.\n\nAcknowledgements\n================\n\nI am grateful to the people who made [R](https://www.r-project.org/), and to [Hadley Wickham](http://hadley.nz/) for making such good packages (and open access books describing them), that allow even low-skilled and low-talented programmers like myself to be able to contribute to R. This package makes use of: [ggplot2](http://ggplot2.tidyverse.org/), [Shiny](http://shiny.rstudio.com/), [stringr](http://stringr.tidyverse.org/), [plotly](https://plot.ly/r/), [readr](http://readr.tidyverse.org/), [readxl](http://readxl.tidyverse.org/), [haven](http://haven.tidyverse.org/), and [RColorBrewer](https://cran.r-project.org/web/packages/RColorBrewer/RColorBrewer.pdf). Package development through [RStudio](https://www.rstudio.com/) and [Github](https://github.com/), and with the help of [R Markdown](http://rmarkdown.rstudio.com) and [devtools](https://www.rstudio.com/products/rpackages/devtools/). The code that allows for online data input was based somewhat on the [BoxPlotR Shiny app](https://github.com/VizWizard/BoxPlotR.shiny). Many thanks to Wilmer Joling who set up the magical \"[docker](https://www.docker.com/)\" and [website](https://site.shinyserver.dck.gmw.rug.nl/ggplotgui/) where the online version of this packages runs.\n"
  },
  {
    "path": "cran-comments.md",
    "content": "## Test environments\n* local OS X install, R 3.5.1\n* Ubuntu xenial (on travis-ci), R 4.0.0\n* win-builder (devel and release)\n\n## R CMD check results\nThere were no ERRORs or WARNINGs or NOTEs\n\nThere was 1 NOTE (only in the 'win-builder'):\n\n* Found the following (possibly) invalid URLs:\nhttp://ggplot2.org/\nhttps://cran.r-project.org/web/packages/RColorBrewer/RColorBrewer.pdf\nhttps://www.rstudio.com/products/rpackages/devtools/\n\n"
  },
  {
    "path": "ggplotgui.Rproj",
    "content": "Version: 1.0\n\nRestoreWorkspace: Default\nSaveWorkspace: Default\nAlwaysSaveHistory: Default\n\nEnableCodeIndexing: Yes\nUseSpacesForTab: Yes\nNumSpacesForTab: 2\nEncoding: UTF-8\n\nRnwWeave: Sweave\nLaTeX: pdfLaTeX\n\nAutoAppendNewline: Yes\nStripTrailingWhitespace: Yes\n\nBuildType: Package\nPackageUseDevtools: Yes\nPackageInstallArgs: --no-multiarch --with-keep.source\n"
  },
  {
    "path": "man/ggplot_shiny.Rd",
    "content": "% Generated by roxygen2: do not edit by hand\n% Please edit documentation in R/ggplot_shiny.R\n\\name{ggplot_shiny}\n\\alias{ggplot_shiny}\n\\title{Creating a graphical user interface for creating ggplot-graphs.}\n\\usage{\nggplot_shiny(dataset = NA)\n}\n\\arguments{\n\\item{dataset}{A dataset (optional).}\n}\n\\value{\nA GUI for visualizing data from \\code{dataset}.\n}\n\\description{\nCreating a graphical user interface for creating ggplot-graphs.\n}\n\\examples{\n#ggplot_shiny()\n#ggplot_shiny(mpg)\n}\n"
  }
]