fancyplots
fancyplots
The goal of fancyplots is to make logarithmically scaled x axis scatter plots and nothing more.
Installation
You can install the released version of fancyplots from my github repo with:
devtools::install_github("kaitsull/fancyplots")
How it was made with devtools
!
- First, after loading the
devtools
package, I instantiated the package with the command:create_tidy_package("fancyplots")
and then created a git repo on my local computer viause_git
. - Then I created my function script via
use_r("scatter_plot_logx")
, and added documentation usingroxygen2
special commenting with the#'
symbol combination. - Since my function requires
ggplot2
, I added this dependency to my description file usinguse_package("ggplot2")
- Then, I used the
use_test("scatterplot")
command (via first using theuse_testthat()
function) to write multiple tests which I checked via thecheck()
function! - Once my tests ran without failure, I instantiated this README.md
file (via
use_readme_rmd()
andbuild_readme()
) - as well as a vignette (viause_vignettes()
andbuild_vingnettes()
) - Finally, I linked up this package to my github repo using
use_github()
BONUS: 1. badges (at top of readme) 2. Website 3. Changelog for release 4. Code of conduct (in repo)
Examples with scatter_plot_logx
making scatterplots with a logarithmically scaled x axis!!!
(the only function in this package :sweat_smile:)
Example 1: Numerical Y Axis
Here is how fancyplots
scatter_plot_x function works with the
gapminder dataset. In this example, our y axis will be lifeExp, which
contains the average life expectancy of each country over the years.
This graph shows population vs life expectancy in the countries of Asia from 1952-2007.
library(fancyplots)
example1 <- filter(gapminder, continent == "Asia")
scatter_plot_logx(example1, "pop", "lifeExp")
#> Removing NA values from the data set...
#> Plotting columns "pop" vs "lifeExp"
#> Printing plot...
Example 2: Factors as the Y Axis
Here is how fancyplots
scatter_plot_x function works with the
gapminder dataset. In this example, our y axis will be continent.
This graph shows us the spread of the population in the countries of each continent in 2007.
library(fancyplots)
example2 <- filter(gapminder, year == 2007)
scatter_plot_logx(example2, "pop", "continent")
#> Removing NA values from the data set...
#> Plotting columns "pop" vs "continent"
#> Printing plot...
Default Features
na.omit
The scale_log_x
by default removes any NA’s within your dataset via
na.omit = TRUE!
Below is plotting of example 1 with multiple NAs inserted.
#adding NAs to rows 150-250
example1[150:250, ] <- NA
scatter_plot_logx(example1, "pop", "lifeExp", na.omit = TRUE)
#> Removing NA values from the data set...
#> Plotting columns "pop" vs "lifeExp"
#> Printing plot...
#> Warning: Removed 101 rows containing missing values (geom_point).
logx
The scale_log_x
by default scales the x axis of your plot via logx
= TRUE!
Below is example 2, plotting with logx = FALSE
scatter_plot_logx(example2, "pop", "continent", logx = FALSE)
#> Removing NA values from the data set...
#> Plotting columns "pop" vs "continent"
#> Printing plot...
verbose
Finally, the scale_log_x
by default has a verbose option set to
TRUE! This prints those update messages one sees prior to the plot. You
can similarly turn off these messages by making verbose equal to
FALSE.