knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
devtools::load_all() library(xgx) library(scales) library(ggplot2) library(dplyr) library(stringr) library(gridExtra)
This sets the default background to white with light grey lines for the at the major and minor breaks. This minimizes chart ink as recommended by Edward Tufte.
xgx_theme_set()
This version of the log scale function shows the tick marks between the major breaks (i.e. at 1, 2, 3, ... 10, instead of just 1 and 10). It also uses $$10^x$$ notation when the labels are base 10 and are very small or very large (<.001 or >9999)
data=data.frame(x=c(rep(0,100),rlnorm(1000,0,1)), y=c(rlnorm(1000,0,5),rep(0,100))) g = ggplot(data,aes(x=x,y=y)) + geom_point() + xgx_scale_x_log10() + xgx_scale_y_log10() print(g) data=data.frame(x=c(rep(0,100),rlnorm(1000,0,1)), y=c(rlnorm(1000,0,.1),rep(0,100))) g = g %+% data print(g) data=data.frame(x=c(rep(0,100),rlnorm(1000,0,1)), y=c(rlnorm(1000,0,.01),rep(0,100))) g = g %+% data print(g) data=data.frame(x=c(rep(-1,100),rlnorm(1000,0,1)), y=c(rlnorm(1000,0,.001)+2,rep(0,100))) g = g %+% data print(g)
Question, should the breaks function contain any kind of error checking for 0 or negative numbers? I'm not sure how ggplot2 checks for this. The code below would cause an error.
breaks.y = xgx_breaks_log10(c(0,10));
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.