{"id":17590930,"url":"https://github.com/vindaar/ggplotnim","last_synced_at":"2025-04-22T19:56:12.098Z","repository":{"id":35426491,"uuid":"188495430","full_name":"Vindaar/ggplotnim","owner":"Vindaar","description":"A port of ggplot2 for Nim","archived":false,"fork":false,"pushed_at":"2024-09-05T09:22:58.000Z","size":48767,"stargazers_count":177,"open_issues_count":27,"forks_count":15,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-10-22T22:56:40.431Z","etag":null,"topics":["data-visualization","ggplot2","hacktoberfest","nim-lang","plot","plotting"],"latest_commit_sha":null,"homepage":"https://vindaar.github.io/ggplotnim","language":"Nim","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Vindaar.png","metadata":{"files":{"readme":"README.org","changelog":"changelog.org","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-05-24T22:40:37.000Z","updated_at":"2024-09-12T13:19:47.000Z","dependencies_parsed_at":"2024-01-31T13:30:29.821Z","dependency_job_id":"2f4f91d0-bca2-4da4-8079-df5de5c74f7d","html_url":"https://github.com/Vindaar/ggplotnim","commit_stats":null,"previous_names":[],"tags_count":83,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vindaar%2Fggplotnim","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vindaar%2Fggplotnim/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vindaar%2Fggplotnim/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vindaar%2Fggplotnim/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Vindaar","download_url":"https://codeload.github.com/Vindaar/ggplotnim/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250315638,"owners_count":21410473,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data-visualization","ggplot2","hacktoberfest","nim-lang","plot","plotting"],"created_at":"2024-10-22T04:43:43.226Z","updated_at":"2025-04-22T19:56:12.053Z","avatar_url":"https://github.com/Vindaar.png","language":"Nim","readme":"* ggplotnim - ggplot2 in Nim\n[[https://github.com/Vindaar/ggplotnim/workflows/ggplotnim%20CI/badge.svg]]\n[[https://matrix.to/#/#nim-science:envs.net][https://img.shields.io/static/v1?message=join%20chat\u0026color=blue\u0026label=nim-science\u0026logo=matrix\u0026logoColor=gold\u0026style=flat-square\u0026.svg]]\n[[https://discord.gg/f5hA9UK3dY][https://img.shields.io/discord/371759389889003530?color=blue\u0026label=nim-science\u0026logo=discord\u0026logoColor=gold\u0026style=flat-square\u0026.svg]]\n\nThis package, as the name suggests, will become a \"sort of\" port of\n[[https://ggplot2.tidyverse.org/][ggplot2]] for Nim. \n\nIt is based on the [[https://github.com/vindaar/ginger/][ginger]] package. \n\nIf you're unfamiliar with the Grammar of Graphics to create plots, one\nof the best resources is probably Hadley Wickham's book on =ggplot2=,\nfor which also an online version exists at:\nhttps://ggplot2-book.org/\n\nIn general this library tries (and will continue to do so) to stay\nmostly compliant with the =ggplot2= syntax. So searching for a\nsolution in =ggplot2= should hopefully be applicable to this (unless\nthe feature isn't implemented yet of course).\n\n** Note on version =v0.4.0=\n\nThe dataframe implementation that was part of this library until\nversion =v0.4.0= is now in its own repository under the name of\n=Datamancer=:\n\n[[https://github.com/SciNim/Datamancer]]\n\nThis library imports and exports =Datamancer=, as such you don't need to\nchange any code, even if you only imported =ggplotnim= to access the dataframe.\n\n** Recipes\n\nFor a more nimish approach, check out the [[file:recipes.org][recipes]], which should give\nyou examples for typical use cases and things I encountered and the\nsolutions I found. Please feel free to add examples to this file to\nhelp other people!\n\nNote that all recipes shown there are part of the test suite. So it's\nguaranteed that the plots shown there for a given version actually\nproduce the shown result!\n\n** Documentation\n\nThe documentation is found at:\n\nhttps://vindaar.github.io/ggplotnim\n\n** Installation \u0026 dependencies\n\nInstallation should be just a \n#+BEGIN_SRC sh\nnimble install ggplotnim\n#+END_SRC\naway. Maybe consider installing the =#head=, since new version\nprobably won't be released after every change, due to rapid\ndevelopment still ongoing.\n\nSince this library is written from scratch there is only a single\nexternal dependency, which is =cairo=.\n\n*** Windows\n\nUsing =ggplotnim= on Windows is made slightly more problematic,\nbecause of the default =cairo= backend. Installing =cairo= on Windows\nis not as straightforward as on Linux or OSX.\n\nThere are multiple options, from most complicated to easiest:\n- installing a program, which also uses =cairo= on Windows, for\n  example =emacs= and adding said program to Windows' PATH. Some\n  instructions here:\n  https://gist.github.com/Vindaar/6cb4e93baff3e1ab88a7ab7ed1ae5686\n- using @pietroppeter's approach to only install the shared libraries\n  that are actually required, see here:\n  https://gist.github.com/pietroppeter/80266c634b22b3861273089dab3e1af2\n- or to thank @preshing's work and use his standalone single DLL for\n  =cairo= on windows:\n  https://github.com/preshing/cairo-windows/\n  See how it's used in the Github Actions workflow for Windows here:\n  https://github.com/Vindaar/ggplotnim/blob/master/.github/workflows/ci.yml#L61-L64\n\nPersonally I would recommend the last option. Note however that the\nstandalone DLL is called =cairo.dll=, but =ggplotnim= expects the name\n=libcairo-2.dll=. I would recommend to put the DLL in some sane place\nand adding that location to your Windows PATH variable:\n\nSimple text only instructions on how to do that:\n#+begin_quote\n- =Win= key\n- search for \"path\"\n- click on “edit system environment variables”\n- click on “Environment Variables” in the bottom right corner\n- under “System variables” select “PATH” and click edit\n- click “New” and add the full path to your installation location of\n  choice that contains the now called =libcairo-2.dll=\n#+end_quote\n\nAfter saving those changes and restarting PowerShell / the command\nprompt everything should work.\n\n** Currently working features\n\nGeoms:\n- =geom_point=\n- =geom_line=\n- =geom_histogram=\n- =geom_freqpoly=\n- =geom_bar= \n- =geom_errorbar=\n- =geom_linerange=\n- =geom_tile=\n- =geom_raster=  \n- =geom_text=\n- =geom_ridgeline= \n- *soon:*\n  - =geom_density=\n\nFacets:\n- =facet_wrap=\n\nScales:\n- size (both for discrete and continuous data)\n- color (both for discrete and continuous data)\n- shape (multiple shapes for lines and points) \n\n** Examples\n\n*Consider looking at the [[file:recipes.org][recipes]] in addition to the below to get a\nfuller picture!*\n\nThe following is a short example from the recipe section that shows\nmultiple features:\n- parsing CSV files to a DF\n- performing DF operations using formulas (=f{}= syntax)\n- general =ggplot= functionality\n- composing multiple geoms to annotate specific datapoints\n\n#+BEGIN_SRC nim\nimport ggplotnim \nlet df = toDf(readCsv(\"data/mpg.csv\"))\nlet dfMax = df.mutate(f{\"mpgMean\" ~ (`cty` + `hwy`) / 2.0})\n  .arrange(\"mpgMean\")\n  .tail(1)\nggplot(df, aes(\"hwy\", \"displ\")) + \n  geom_point(aes(color = \"cty\")) + # set point specific color mapping\n  # Add the annotation for the car model below the point\n  geom_text(data = dfMax,\n            aes = aes(y = f{c\"displ\" - 0.2}, \n                      text = \"model\")) +\n  # and add another annotation of the mean mpg above the point\n  geom_text(data = dfMax,\n            aes = aes(y = f{c\"displ\" + 0.2}, \n                      text = \"mpgMean\")) +\n  theme_opaque() +\n  ggsave(\"media/recipes/rAnnotateMaxValues.png\")\n#+END_SRC\n\n\n[[./media/recipes/rAnnotateMaxValues.png]]\n\n** *Experimental* Vega-Lite backend\n\nFrom the beginning one of my goals for this library was to provide not\nonly a Cairo backend, but also to support [[https://vega.github.io/vega-lite/][Vega-Lite]] (or possibly Vega)\nas a backend. \nTo share plots and data online (and possibly add support for\ninteractive features) is much easier in such a way.\n\nAn experimental version is implemented in [[https://github.com/Vindaar/ggplotnim/blob/master/src/ggplotnim/ggplot_vega.nim][ggplot_vega.nim]], which\nprovides most functionality of the native backend, with the exception\nof support for facetted plots.\n\nSee the [[https://github.com/Vindaar/ggplotnim/blob/master/recipes.org#simple-vega-lite-example][full example in the recipe here]].\n\nCreating a vega plot is done by also importing the =ggplot_vega=\nsubmodule and then just replacing a =ggsave= call by a =ggvega= call:\n#+begin_src nim\nimport ggplotnim\nimport ggplotnim/ggplot_vega\nlet mpg = toDf(readCsv(\"data/mpg.csv\"))\nggplot(mpg, aes(x = \"displ\", y = \"cty\", color = \"class\")) +\n  geom_point() +\n  ggtitle(\"ggplotnim in Vega-Lite!\") +\n  ggvega(\"media/recipes/rSimpleVegaLite.html\") # w/o arg creates a `/tmp/vega_lite_plot.html`\n#+end_src\n\nThis recipe gives us the following plot:\n\n[[media/recipes/rSimpleVegaLite.png]]\n\nTo view it as an interactive plot in the Vega viewer, [[https://vega.github.io/editor/?#/gist/0bef3ed0cf7c6d26da927732f1c81582/rSimpleVegaLite.json][click here]].\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvindaar%2Fggplotnim","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvindaar%2Fggplotnim","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvindaar%2Fggplotnim/lists"}