All Projects → stefanedwards → Lemon

stefanedwards / Lemon

Licence: gpl-3.0
🍋 Lemon --- Freshing up your ggplots

Programming Languages

r
7636 projects

Projects that are alternatives of or similar to Lemon

Ggpol
🌍 Parliament diagrams and more for ggplot2
Stars: ✭ 71 (-51.7%)
Mutual labels:  ggplot2, ggplot-extension
Gganimate
A Grammar of Animated Graphics
Stars: ✭ 1,744 (+1086.39%)
Mutual labels:  ggplot2, ggplot-extension
ggdogs
The geom you always wished for adding dogs to ggplot2
Stars: ✭ 28 (-80.95%)
Mutual labels:  ggplot2, ggplot-extension
Calendr
Ready to print calendars with ggplot2
Stars: ✭ 161 (+9.52%)
Mutual labels:  ggplot2, ggplot-extension
Ggbernie
A ggplot2 geom for adding Bernie Sanders to ggplot2
Stars: ✭ 96 (-34.69%)
Mutual labels:  ggplot2, ggplot-extension
Gghalves
✂️ Easy half-half geoms in ggplot2
Stars: ✭ 174 (+18.37%)
Mutual labels:  ggplot2, ggplot-extension
Ggsignif
Easily add significance brackets to your ggplots
Stars: ✭ 322 (+119.05%)
Mutual labels:  ggplot2, ggplot-extension
Ggpointdensity
📈 📊 Introduces geom_pointdensity(): A Cross Between a Scatter Plot and a 2D Density Plot.
Stars: ✭ 286 (+94.56%)
Mutual labels:  ggplot2, ggplot-extension
Ggraph
Grammar of Graph Graphics
Stars: ✭ 815 (+454.42%)
Mutual labels:  ggplot2, ggplot-extension
Ggforce
Accelerating ggplot2
Stars: ✭ 640 (+335.37%)
Mutual labels:  ggplot2, ggplot-extension
Econocharts
Microeconomics/macroeconomics charts in ggplot2
Stars: ✭ 161 (+9.52%)
Mutual labels:  ggplot2, ggplot-extension
Hrbrthemes
🔏 Opinionated, typographic-centric ggplot2 themes and theme components
Stars: ✭ 899 (+511.56%)
Mutual labels:  ggplot2, ggplot-extension
Patchwork
The Composer of ggplots
Stars: ✭ 2,002 (+1261.9%)
Mutual labels:  ggplot2, ggplot-extension
ggbg
Miscellaneous Ggplot2 Extensions
Stars: ✭ 21 (-85.71%)
Mutual labels:  ggplot2, ggplot-extension
Ggh4x
ggplot extension: options for tailored facets, multiple colourscales and miscellaneous
Stars: ✭ 148 (+0.68%)
Mutual labels:  ggplot2, ggplot-extension
Ggalt
🌎 Extra Coordinate Systems, Geoms, Statistical Transformations & Scales for 'ggplot2'
Stars: ✭ 561 (+281.63%)
Mutual labels:  ggplot2, ggplot-extension
Ggdistribute
ggplot2 extension for plotting distributions
Stars: ✭ 16 (-89.12%)
Mutual labels:  ggplot2, ggplot-extension
Ggcats
The geom you always wished for adding cats to ggplot2
Stars: ✭ 34 (-76.87%)
Mutual labels:  ggplot2, ggplot-extension
Wraprmd
RStudio addin for wrapping RMarkdown paragraphs
Stars: ✭ 87 (-40.82%)
Mutual labels:  knitr
Printr
Some (magical) printing methods for knitr
Stars: ✭ 117 (-20.41%)
Mutual labels:  knitr

Lemon --- Freshing up your ggplots

CRAN_Status_Badge downloads

Just another ggplot2 and knitr extension package.

This package contains functions primarily in these domains of ggplot2:

  • Axis lines miniature Axis lines.
  • Facets miniature Repeated axis lines on facets.
  • geom_pointline geom_pointpath and geom_pointline.
  • Legends

As well as some functions in knitr.

Installation

# install.packages("devtools")

# Install release from GitHub:
devtools::install_github("stefanedwards/lemon", ref='v0.3.1')

# Or get the lastest development version from GitHub:
devtools::install_github("stefanedwards/lemon")

Axis lines

We can display a limit on the axes range.

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):

(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:

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.

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:

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, we bring you g_legend:

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/] (https://github.com/tidyverse/ggplot2/wiki/Share-a-legend-between-two-ggplot2-graphs) and (Shaun Jackman)[http://rpubs.com/sjackman] (http://rpubs.com/sjackman/grid_arrange_shared_legend). We put it in a package.

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:

Viewing data frames in R Notebooks in RStudio

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.

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:

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.

dat <- read.table(.data('mydata.tab'))
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].