Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/brandmaier/ggx
ggx
https://github.com/brandmaier/ggx
Last synced: about 14 hours ago
JSON representation
ggx
- Host: GitHub
- URL: https://github.com/brandmaier/ggx
- Owner: brandmaier
- Created: 2020-12-09T20:02:58.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-10-25T11:49:41.000Z (about 2 years ago)
- Last Synced: 2024-08-03T06:03:07.402Z (3 months ago)
- Language: R
- Size: 2.6 MB
- Stars: 145
- Watchers: 6
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.Rmd
- Changelog: Changes.md
Awesome Lists containing this project
README
---
output: github_document
---```{r, echo = FALSE, message=FALSE, warning=FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
fig.width = 3,
fig.height = 3,
out.width = "50%"
)library(ggplot2)
library(ggx)theme_set(theme_classic())
```
# ggx
[![cran version](http://www.r-pkg.org/badges/version/ggx)](https://cran.r-project.org/package=ggx)
[![rstudio mirror downloads](http://cranlogs.r-pkg.org/badges/ggx)](https://github.com/metacran/cranlogs.app)
[![Total downloads badge](https://cranlogs.r-pkg.org/badges/grand-total/ggx?color=blue)](https://CRAN.R-project.org/ggx)
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-brightgreen.svg)](https://www.tidyverse.org/lifecycle/#experimental)
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
![contributions](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)
![noAI](https://img.shields.io/badge/no-AI-blue)## Overview
This package is an add-on to `ggplot2`, the R package for creating awesome graphics, which is based on [The Grammar of Graphics](https://amzn.to/2ef1eWp). `ggplot2` has changed my life as a scientist and developer. However, I have terrible memory and I forget the same commands again and again. Like, how do you rotate axis labels again? Or how do you hide the legend...? So I often end up searching the net for help and then I copy and paste the solution I find into my R script. And I know at least one more person who does this, too. Eventually, I wondered whether we couldn't save this extra step and just _talk_ to ggplot in natural language (similar to a Google search query). So, I wrote this package that lets us issue natural language commands, which then are translated into ggplot commands. This is very likely totally bonkers, and this is how it looks (watch the `gg_` commands below):
```{r overview_usage, warning=FALSE, message=FALSE}
ggplot(data=cars,aes(x=speed, y=dist))+geom_point()+
gg_("rotate x-axis labels by 90 degrees")+
gg_("increase font size on x-axis label")
```## Disclaimer
I am pretty sure that this package violates fundamental principles of ggplot2. First and foremost, it would be much wiser to just study and learn the respective commands instead of relying on fuzzy and not well-defined natural language commands. Second, this package doesn't rely on fancy deep learning or other AI technology. It's a simple keyword matching algorithm. If someone fancies to replace this with a better approach, please do so. Contributions to this package are more then welcome!
## Installation
Either install the latest stable version from CRAN:
```{r eval=FALSE}
install.packages("ggx")
```Or, install the development version from GitHub:
```{r, eval = FALSE}
# install.packages("devtools")
devtools::install_github("brandmaier/ggx")
````## Usage Examples
You can find more examples and use cases on the package website:
[here](https://brandmaier.github.io/ggx/)
This package has two basic modes of operations. Either you use the `gg_(...)` command to generate ggplot2 elements from natural language and chain them directly to your plotting commands (for lazy people), or you use the package as a reminder of the command and let the package print out the command, which you then copy and paste to your code (safer option). In the following, I will give you a few examples of how the package could be used. Assume, we start off with basic 2D plot of Fisher's classic iris data:```{r example_basic}
ggplot(data=iris,
mapping=aes(x=Sepal.Length,
y=Petal.Length, color=Species))+
geom_point()
```Now, if we want to hide the legend and don't remember the ggplot command to do so, we can use the `gg_()` short-hand to express our request in natural language:
```{r example_hide_legend}
ggplot(data=iris,
mapping=aes(x=Sepal.Length,
y=Petal.Length, color=Species))+
geom_point()+
gg_("hide legend")
```Or, say we want to rotate the labels of the x axis and rename the axis label:
```{r example_rotate_labels}
ggplot(data=iris,
mapping=aes(x=Sepal.Length,
y=Petal.Length, color=Species))+
geom_point()+
gg_("rotate x-axis labels by 90°")+
gg_("set x-axis label to 'Length of Sepal'")
```Or,
```{r example_increase_fontsize}
ggplot(data=iris,
mapping=aes(x=Sepal.Length,
y=Petal.Length, color=Species))+
geom_point()+
gg_("double the font size on the x-axis label")
```Or,
```{r example_fontcolor}
ggplot(data=iris,
mapping=aes(x=Sepal.Length,
y=Petal.Length, color=Species))+
geom_point()+
gg_("add 'Hello World' as plot title")+
gg_("paint the plot title in a beautiful orange")+
gg_("set the color of the x-axis label to blue")
```If you want to go the safer route, just use the `ggx` package as personal assistant that helps you find solutions to common graph formatting problems, like in the following:
```{r}
gghelp("How can I hide the graph legend?")
```Or,
```{r}
gghelp("I want to flip my x-axis and y-axis.")
```Or,
```{r}
gghelp("How can I increase the font size on the x axis?")
```Since `ggx` is matching keywords, it allows for some variation in how the question is put:
```{r}
gghelp("I want to remove my plot legend")
gghelp("Please hide the legend")
gghelp("Get rid of that stupid legend")
```Colors and numbers are parsed and inserted into the final commands:
```{r}
gghelp("Rotate the x-axis labels by 56 degrees")gghelp("Paint the label of the y-axis in green")
```## Other Solutions
There is a nice little package called [ggeasy](https://jonocarroll.github.io/ggeasy/) that addresses the same problem. However, it defines yet another set of commands, like this:
```{r eval=FALSE}
# rotate x axis labels
ggplot(mtcars, aes(hp, mpg)) +
geom_point() +
easy_rotate_x_labels()
```But I keep forgetting those, too ;)
## Disclaimer (continued)
This package is just a quick and dirty implementation of a keyword matching algorithm. Do not expect any deeper language processing. Neither is this program a therapist (see Eliza or others). Also, the program doesn't aim for completeness. It just knows a couple of commands that I tend to forget. Don't be mad if you hate the package. Just ignore it and write beautiful ggplot code without it. If you like the package, think about contributing to it. Add more questions, keywords, etc. I welcome any contribution, preferably via pull requests on github.