Skip to contents

jbplot includes functions to change the style of ggplot2 plots. The included theme, quo, can be added to individual plots using theme_quo().

Quo Theme

The quo theme applied to the venerable mtcars dataset. Example adapted from ggplot2::theme_minimal():

p1 <- ggplot(mtcars, aes(x = wt, y = mpg, color = factor(cyl))) +
  geom_point() +
  labs(
    title = "Fuel economy declines as weight increases",
    subtitle = "(1973-74)",
    caption = "Data from the 1974 Motor Trend US magazine.",
    tag = "Figure 1",
    x = "Weight (1000 lbs)",
    y = "Fuel economy (mpg)",
    color = "Gears"
  )

p1

Scatterplot of weight versus miles per gallon for 32 cars using the default ggplot2 theme. The points are grouped and colored by the number of cylinders.

p1 + theme_quo()

Scatterplot of weight versus miles per gallon for 32 cars using the quo theme. The points are grouped and colored by the number of cylinders.

The viridis color scheme can be added manually using ggplot2::scale_color_viridis_d():

Scatterplot of weight versus miles per gallon for 32 cars using the quo theme and viridis colors. The points are grouped and colored by the number of cylinders.

Viridis Quo

Quo is designed to be paired with the viridis color scale, added by calling one of the continuous (c) or discrete (d) viridis color scales:

Sample plots using the default theme and color scales:

txsamp <- subset(txhousing, city %in% c("Houston", "Fort Worth", "San Antonio", "Dallas", "Austin"))

(d <- ggplot(data = txsamp, aes(x = sales, y = median)) +
  geom_point(aes(colour = city)))

Scatterplot of number of sales versus median sale price for five cities in Texas. The points are grouped and colored by city. Styled with the default ggplot2 theme.

(p <- ggplot(txsamp, aes(x = median, fill = city)) +
  geom_histogram(position = "dodge", binwidth = 15000))

Histogram of median sales price for five cities in Texas, with different colored bars for each city. Styled with the default ggplot2 theme.

(v <- ggplot(faithfuld) +
  geom_raster(aes(waiting, eruptions, fill = density)))

A 2D density estimate of the waiting time between eruptions and the duration of the eruption for the Old Faithful geyser in Yellowstone National Park. Styled with the default ggplot2 theme.

The same plots after applying viridis and quo:

Scatterplot of number of sales versus median sale price for five cities in Texas. The points are grouped and colored by city. Styled with the quo theme and viridis colors.

Histogram of median sales price for five cities in Texas, with different colored bars for each city. Styled with the quo theme and viridis colors.

A 2D density estimate of the waiting time between eruptions and the duration of the eruption for the Old Faithful geyser in Yellowstone National Park. Styled with the quo theme and viridis colors.

Grid lines

Grid lines can be selectively disabled using theme_quo():

d + scale_color_viridis_d() + theme_quo(minor = FALSE)

Scatterplot of number of sales versus median sale price for five cities in Texas. The points are grouped and colored by city. Styled with the quo theme and viridis colors, with only major grid lines.

p + scale_fill_viridis_d() + theme_quo(x = FALSE)

Histogram of median sales price for five cities in Texas, with different colored bars for each city. Styled with the quo theme and viridis colors, using only horizontal grid lines.

v + scale_fill_viridis_c() + theme_quo(major = FALSE, minor = FALSE)

A 2D density estimate of the waiting time between eruptions and the duration of the eruption for the Old Faithful geyser in Yellowstone National Park. Styled with the quo theme and viridis colors, with no grid lines.