theme_x is a
ggplot2 custom theme that generates plots similar to base R.
The main idea is to go for a clean, uncluttered layout that focuses the viewer's attention on the details of the plot. The base R visualizations are very good at that and I've always wanted that in
I tweaked the spacing and alignment of text elements so that they can “breathe” more. Plots may be about shapes and colors, yet text should not be neglected. Inconsolata is the default font. It's readable and displays digits nicely.
The usage is straight-forward. You just add
theme_x() at the end of any
ggplot2 plot object.
The inspiration for this small package comes from Jeffrey B. Arnold's
Run these 3 lines of code.
install.packages("devtools") require(devtools) install_github("xslates/theme_x")
library(ggplot2) library(themex) ggplot(cars, aes(speed, dist)) + geom_point() + labs(title = "Cars Dataset", subtitle = "Speed and Stopping Distances of Cars", caption = "R dataset") + theme_x()
orange <- Orange orange %>% ggplot(aes(age, circumference, fill = Tree)) + geom_area(color = "black") + labs(title = "Age and circumference of orange trees", subtitle = "Older trees grow larger", x = "age (in days)", caption = "the Orange data frame has 35 rows and 3 columns of records of the growth of orange trees") + facet_grid(. ~ Tree) + theme_x()
ToothGrowth$dose <- as.factor(ToothGrowth$dose) ggplot(ToothGrowth, aes(x = dose, y = len, fill = dose)) + geom_dotplot(binaxis = 'y', stackdir = 'center') + labs(title = "Tooth growth in ginuea pigs", subtitle = "After receiving experimental C-vitamine treatment", caption = "Experiment") + theme_x()
set.seed(1234) df <- data.frame( sex = factor(rep(c("F", "M"), each = 200)), weight = round(c(rnorm(200, mean = 55, sd = 5), rnorm(200, mean = 65, sd = 5)))) mu <- ddply(df, "sex", summarise, grp.mean=mean(weight)) ggplot(df, aes(x = weight, fill = sex)) + geom_density(alpha = 0.4) + geom_vline(data = mu, aes(xintercept = grp.mean, color = sex), linetype = "dashed") + labs(title = "Body weight density plot", subtitle = "Dotted line is the mean weight", caption = "weight in kilograms") + theme_x()
set.seed(1) x1 <- 100 + arima.sim(model = list(ar = 0.999), n = 100) y <- 1.2 * x1 + rnorm(100) y[71:100] <- y[71:100] + 10 data <- cbind(y, x1) pre.period <- c(1, 70) post.period <- c(71, 100) impact <- CausalImpact(data, pre.period, post.period) plot(impact) + labs(title = "Causal Impact", subtitle = "From Causal Impact: R package that implements an approach to estimating the causal effect of a designed intervention on a time series", caption = "An R package for causal inference using Bayesian structural time-series models") + theme_x()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.