title | author | date | output | vignette |
---|---|---|---|---|
R package ggplotAssist |
Keon-Woong Moon |
2017-10-24 |
rmarkdown::html_vignette |
%\VignetteIndexEntry{ggplotAssist} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8}
|
The 'ggplotAssist' is an RStudio addin for teaching and learning plot generation using the 'ggplot2' package. You can learn each steps of plot generation - aesthetics mapping, select geometries, add scales, apply theme - by clicking your mouse without coding. You can see the resultant plot and see the each steps of plot layer by layer. You get resultant code for ggplot.
You have to install the developmental version of R package editData
from github.
#install.packages("devtools")
devtools::install_github("cardiomoon/editData")
You can install ggplotAssist
package from github.
#install.packages("devtools")
devtools::install_github("cardiomoon/ggplotAssist")
This addin can be used to interactively generate a ggplot
using ggplot2
package.
The intended way to use this is as follows:
- Highlight a symbol naming a
data.frame
or atibble
in your R session, e.g.msleep
(1). Execute this addin(arrow), to interactively manipulate it.
- You can see a brower window. You can see the data name(1) and R code for ggplot(2). Select
x
(3) andbodywt
(4) to mapbodywt
as a x-axis variable.
- You can see the R code for ggplot(1). Select
y
andbrainwt
to map the y-axis variable.
- To add geoms to ggplot, press
geom
button(1) and selectgeom_point
(2). You can mapping or setting the aesthetics of geom_point. You can see the R code for this layer(3). In the lower part of window, you can see two R codes and two plots. In the lower left portion, you can see the R code for plot(4) and resultant plot(5). In the lower right portion, you can see the R code for plot with R code for layer under construction(6) and resultant plot(7). This is a plot preview.
- If you finish to make a layer, press
Add Layer
button(1) to add the layer. You can see added layers(2). You can delete a layer withdelete layer
button after select a layer to delete.
- To add theme, press
theme
button(1) and selecttheme_bw
(2). You can see the code for theme_bw(3) and plot preview(4,5). PressAdd Layer
button(6) to add the code.
- To apply a log scale to x-axis, press
scale
button(1) and selectscale_x_log10
function(2). You can set the arguments of scale_x_log10() function(3). You can see the code for scale(4) and plot preview(5,6). To add math format to the log scale, pressAdd math-format
button(9). You can repeat this step to apply a log scale to y-axis.
- You can add logticks to your plot. Press
annotate
button(1) and select annotation_logticks function(2). You can see the arguments and default values of this function(3). Set the side argumenttrbl
(4). You can see the R code for this layer(5) and plot preview(6.7). PressAdd Layer
button(8) to add this layer.
- You can hide the minor grid lines because they don't align with the ticks. Press
theme
button(1) and select thetheme
function(2). Thetheme()
function has a lot of arguments. Selectpanel.grid.minor
argument(3) and selectelement_blank()
(4) to hide the minor grid line.
- You can see this plot layer by layer. Press the
Layer by layer
button(1) and use the sliderInput to see the plot layer by layer. You can animate this plot by click the arrowhead(2). If you want to get this R code for plot, pressDone
button(3).
- When you're done, the code for the ggplot will be emitted at the cursor position(scarlet rectangle).
You can use the ggplotAssist()
function as a regular function, e.g. in a command line.
result <- ggplotAssist(mtcars)