Science Score: 36.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
βCITATION.cff file
-
βcodemeta.json file
Found codemeta.json file -
β.zenodo.json file
Found .zenodo.json file -
βDOI references
-
βAcademic publication links
-
βCommitters with academic emails
1 of 6 committers (16.7%) from academic institutions -
βInstitutional organization owner
-
βJOSS paper metadata
-
βScientific vocabulary similarity
Low similarity (11.0%) to scientific vocabulary
Keywords
axis-lines
facets
ggplot-extension
ggplot2
knitr
legend
ticks
visualization
Last synced: 6 months ago
·
JSON representation
Repository
π Lemon --- Freshing up your ggplots
Basic Info
- Host: GitHub
- Owner: stefanedwards
- License: gpl-3.0
- Language: R
- Default Branch: master
- Homepage: https://cran.r-project.org/package=lemon
- Size: 798 KB
Statistics
- Stars: 194
- Watchers: 7
- Forks: 14
- Open Issues: 6
- Releases: 6
Topics
axis-lines
facets
ggplot-extension
ggplot2
knitr
legend
ticks
visualization
Created almost 9 years ago
· Last pushed 6 months ago
Metadata Files
Readme
Changelog
License
README.Rmd
---
output: github_document
---
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README/",
cache.path = "README/cache/",
cache = TRUE,
autodep=TRUE,
cache.rebuild = TRUE
)
```
# Lemon --- Freshing up your ggplots
[](https://cran.r-project.org/package=lemon)

[](https://github.com/stefanedwards/lemon/actions/workflows/R-CMD-check.yaml)
Just another [ggplot2](http://ggplot2.tidyverse.org) and
[knitr](https://yihui.name/knitr/) extension package.
This package contains functions primarily in these domains of ggplot2:
```{r domain_axis_lines,include=FALSE,fig.height=0.5,fig.width=0.5}
library(ggplot2)
library(lemon)
ggplot(mtcars, aes(x=cyl, y=mpg)) +
geom_point(size=0.1) +
coord_capped_cart(bottom=brackets_horisontal(), left='both') +
theme_light() +
theme(panel.border=element_blank(), axis.line = element_line(),
axis.title=element_blank(), axis.text=element_blank(),
panel.grid=element_blank(), axis.ticks.x = element_line(colour='black'))
```
```{r domain_facets,include=FALSE,fig.height=0.5, fig.width=0.5}
ggplot(mtcars, aes(x=cyl, y=mpg)) +
geom_point(size=0.1) +
coord_capped_cart(bottom='both', left='both') +
facet_rep_wrap(~carb) +
theme_light() +
theme(panel.border=element_blank(), axis.line = element_line(),
axis.title=element_blank(), axis.text=element_blank(),
panel.grid=element_blank(), axis.ticks = element_blank(),
axis.ticks.length = unit(0, 'npc'), panel.spacing=unit(1, 'mm'),
strip.background=element_blank(), strip.text=element_blank())
```
```{r domain_pointline,include=FALSE,fig.height=0.5,fig.width=0.5}
ggplot(data.frame(x=1:3, y=c(1,2.4,3.5)), aes(x, y)) +
geom_pointline(size=0.5) +
coord_capped_cart(xlim=c(0,4), bottom='both', left='both') +
theme_light() +
theme(panel.border=element_blank(), axis.line = element_line(),
axis.title=element_blank(), axis.text=element_blank(),
panel.grid=element_blank(), axis.ticks.x = element_line(colour='black'))
```
-  Axis lines.
-  Repeated axis lines on facets.
-  `geom_pointpath` and `geom_pointline`.
- Legends
As well as some functions in knitr.
## Installation
```{r, eval = FALSE}
# install.packages("devtools")
# Install release from GitHub:
devtools::install_github("stefanedwards/lemon", ref='v0.4.7')
# Or get the lastest development version from GitHub:
devtools::install_github("stefanedwards/lemon")
```
## Axis lines
We can display a limit on the axes range.
```{r usage1}
library(lemon)
ggplot(mtcars, aes(x=cyl, y=mpg)) +
geom_point() +
coord_capped_cart(bottom='both', left='none') +
theme_light() + theme(panel.border=element_blank(), axis.line = element_line())
```
**NB**: Disable `panel.border` and enable `axis.line` in `theme`, otherwise you will not see an effect!
We could also show that the x-axis is categorical (or ordinal):
```{r brackets_demo}
(p <- ggplot(mtcars, aes(x=as.factor(cyl), y=mpg)) +
geom_point(position=position_jitter(width=0.1)) +
coord_flex_cart(bottom=brackets_horisontal(), left=capped_vertical('both')) +
theme_light() + theme(panel.border=element_blank(), axis.line = element_line())
)
```
When capping the axis lines, they are never capped further inwards than the ticks!
Look up
* `coord_capped_cart`, `coord_capped_flip`
* `coord_flex_cart`, `coord_flex_flip`, `coord_flex_fixed`
* `brackets_horisontal`, `brackets_vertical`
* `capped_horisontal`, `capped_vertical`
## Facets
Having produced such wonderous axes, it is a pity they are not plotted around
all panels when using faceting.
We have extended both `facet_grid` and `facet_wrap` to produce axis, ticks, and
labels on _all_ panels:
```{r facets}
p + facet_rep_wrap(~gear, ncol=2, label=label_both)
```
They work just like the normal ones; look up `facet_rep_grid` and `facet_rep_wrap`.
## `geom_pointline`
A geom that combines both points and lines.
While possible by using both `geom_point` and `geom_line`, position adjustments
are not preserved between the two layers.
`geom_pointline` and `geom_pointpath` combines `geom_point` with
`geom_line` and `geom_path`, respectively, while preserving position adjustments.
```{r geom_pointline_demo,echo=FALSE}
library(grid)
library(gtable)
p <- ggplot(mtcars, aes(wt, mpg, colour=factor(cyl))) +
geom_point(col='grey') +
theme_light() + theme(panel.border=element_blank(), axis.line = element_line()) +
theme(legend.position='hidden', plot.title = element_text(size=rel(0.8)))
p1 <- p + geom_point(position=position_jitter(0.1, 0.1)) + geom_line(position=position_jitter(0.1, 0.1)) +
labs(title='geom_point(position=position_jitter(0.1, 0.1)) + \ngeom_line(position=position_jitter(0.1, 0.1))')
p2 <- p + geom_pointline(position=position_jitter(0.1, 0.1)) +
labs(title='geom_pointline(position=position_jitter(0.1, 0.1))')
g1 <- ggplotGrob(p1)
g2 <- ggplotGrob(p2)
grid.newpage()
grid.draw(cbind(g1, g2, size = 'first'))
```
Left: `geom_point` and `geom_line` as two separate geoms.
Right: The two geoms combined into `geom_pointline`.
Both produced with `ggplot(mtcars, aes(wt, mpg, colour=factor(cyl))) + geom_point(col='grey')`, where the grey points indicate the true location of the datapoint.
An added visual effect is seen as the lines do not touch the points, leaving a
small gap (set by argument `distance`).
## Legends
Reposition the legend onto the plot. Exactly where you want it:
```{r reposition_legend}
dsamp <- diamonds[sample(nrow(diamonds), 1000), ]
d <- ggplot(dsamp, aes(carat, price)) +
geom_point(aes(colour = clarity))
reposition_legend(d, 'top left')
```
The legend repositioned onto the top left corner of the panel.
Scavenging the Internet, we have found some functions that help work with
legends.
Frequently appearing on [Stack Overflow](https://stackoverflow.com), we bring
you `g_legend`:
```{r g_legend,fig.height=3,fig.width=2}
library(grid)
legend <- g_legend(d)
grid.newpage()
grid.draw(legend)
```
The legend grob, by itself.
Originally brought to you by
(Baptiste AuguiΓ©)[http://baptiste.github.io/]
()
and
(Shaun Jackman)[http://rpubs.com/sjackman]
().
We put it in a package.
```{r grid_arrange_shared_legend}
dsamp <- diamonds[sample(nrow(diamonds), 1000), ]
p1 <- qplot(carat, price, data = dsamp, colour = clarity)
p2 <- qplot(cut, price, data = dsamp, colour = clarity)
p3 <- qplot(color, price, data = dsamp, colour = clarity)
p4 <- qplot(depth, price, data = dsamp, colour = clarity)
grid_arrange_shared_legend(p1, p2, p3, p4, ncol = 2, nrow = 2)
```
Four plots that share the same legend.
## Extensions to knitr
`knitr` allows S3 methods for `knit_print` for specialised printing of objects.
We provide `lemon_print` for data frames, dplyr tables, and summary objects,
that can be used to render the output, without mucking up the code source.
An added benefit is that we can use RStudio's inline data frame viewer:

### Relative file paths made safe
Using `knitr` for computations that use external binaries and/or write temporary
files, setting the root directory for `knitr`'s knitting saves the user from a
file mess. E.g.
```r
knitr::opts_knit$set(root.dir=TMPDIR)
```
But we want to keep our file paths relative for the scripts / document to be
transferable. We introduce the `.dot` functions:
```r
TMPDIR=tempdir()
.data <- .dot('data')
knitr_opts_knit$set(root.dir=TMPDIR)
```
We can then load our data file using the created `.data` function,
even though the chunk is executed from TMPDIR.
```r
dat <- read.table(.data('mydata.tab'))
```
Owner
- Name: Stefan McKinnon Edwards
- Login: stefanedwards
- Kind: user
- Location: Silkeborg, Denmark
- Company: Kamstrup A/S
- Website: www.iysik.com
- Twitter: iysik_com
- Repositories: 30
- Profile: https://github.com/stefanedwards
Data Analyst at Kamstrup A/S, former quantitative geneticist.
GitHub Events
Total
- Issues event: 1
- Watch event: 9
- Issue comment event: 5
- Push event: 3
- Pull request event: 3
- Fork event: 1
Last Year
- Issues event: 1
- Watch event: 9
- Issue comment event: 5
- Push event: 3
- Pull request event: 3
- Fork event: 1
Committers
Last synced: over 2 years ago
Top Committers
| Name | Commits | |
|---|---|---|
| stefanedwards | s****e@i****m | 119 |
| Stefan McKinnon HΓΈj-Edwards | s****e@k****m | 32 |
| Stefan Hoj-Edwards | s****s | 7 |
| HOJ-EDWARDS Stefan | s****w@e****k | 2 |
| Teun van den Brand | 4****d | 1 |
| Stefan McKinnon Edwards | s****h@k****m | 1 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 29
- Total pull requests: 9
- Average time to close issues: 12 months
- Average time to close pull requests: 24 days
- Total issue authors: 16
- Total pull request authors: 3
- Average comments per issue: 1.93
- Average comments per pull request: 0.78
- Merged pull requests: 6
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 1
- Pull requests: 3
- Average time to close issues: N/A
- Average time to close pull requests: about 1 month
- Issue authors: 1
- Pull request authors: 2
- Average comments per issue: 0.0
- Average comments per pull request: 1.0
- Merged pull requests: 1
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- stefanedwards (11)
- dylanjm (2)
- g-pacheco (2)
- thomasp85 (2)
- ObGDK (1)
- msgoussi (1)
- mdeber (1)
- teng-gao (1)
- jdeines (1)
- ghost (1)
- bappa10085 (1)
- lnnrtwttkhn (1)
- thomas-neitmann (1)
- gkaramanis (1)
- sam81 (1)
Pull Request Authors
- stefanedwards (5)
- teunbrand (3)
- mariabnd (2)
Top Labels
Issue Labels
bug (7)
enhancement (3)
Pull Request Labels
Packages
- Total packages: 3
-
Total downloads:
- cran 5,393 last-month
- Total docker downloads: 425
-
Total dependent packages: 6
(may contain duplicates) -
Total dependent repositories: 15
(may contain duplicates) - Total versions: 23
- Total maintainers: 1
proxy.golang.org: github.com/stefanedwards/lemon
- Documentation: https://pkg.go.dev/github.com/stefanedwards/lemon#section-documentation
- License: gpl-3.0
-
Latest release: v0.4.7
published over 2 years ago
Rankings
Dependent packages count: 6.5%
Average: 6.7%
Dependent repos count: 6.9%
Last synced:
6 months ago
cran.r-project.org: lemon
Freshing Up your 'ggplot2' Plots
- Homepage: https://github.com/stefanedwards/lemon
- Documentation: http://cran.r-project.org/web/packages/lemon/lemon.pdf
- License: GPL-3
-
Latest release: 0.5.2
published 6 months ago
Rankings
Stargazers count: 2.4%
Downloads: 6.1%
Dependent packages count: 7.3%
Dependent repos count: 7.7%
Forks count: 7.9%
Average: 8.9%
Docker downloads count: 22.1%
Maintainers (1)
Last synced:
6 months ago
conda-forge.org: r-lemon
- Homepage: https://github.com/stefanedwards/lemon
- License: GPL-3.0-only
-
Latest release: 0.4.5
published over 5 years ago
Rankings
Dependent repos count: 24.4%
Stargazers count: 27.9%
Average: 37.8%
Forks count: 47.5%
Dependent packages count: 51.6%
Last synced:
6 months ago
Dependencies
DESCRIPTION
cran
- R >= 3.1.0 depends
- ggplot2 >= 2.2.0 imports
- grid * imports
- gridExtra * imports
- gtable * imports
- knitr >= 1.12 imports
- lattice * imports
- plyr * imports
- scales * imports
- dplyr * suggests
- rmarkdown * suggests
- stringr * suggests
- testthat * suggests