jrnold / ggthemes

Additional themes, scales, and geoms for ggplot2
http://jrnold.github.io/ggthemes/
1.31k stars 229 forks source link

theme_excel_new() doesn't display labels (and base size doesnt work as expected for title) #176

Open Yann-C-INN opened 4 months ago

Yann-C-INN commented 4 months ago

This was originally a bug report issue but I was able to edit the source code and fix it myself, but I couldnt submit a pull request so I attached what I wrote

Problem:

Changes I made:

I did not change axis.title that is set to blank, although I would suggest to not ommit axis labels as a default.

My corrected (and tested) code:

theme_excel_new <- function(base_size=9,
                            base_family = "sans") {
  PT_TO_MM <- 0.352777778
  colorlist <- list(
    lt_gray = "#D9D9D9",
    gray = "#BFBFBF",
    dk_gray = "#595959"
  )
  theme_bw(
    base_family = base_family,
    base_size = base_size
  ) +
    theme(
      text = element_text(
        colour = colorlist$dk_gray,
        size = base_size
      ),
      line = element_line(
        linetype = "solid",
        colour = colorlist$gray
      ),
      rect = element_rect(
        linetype = 0,
        colour = "white"
      ),
      panel.grid.major = element_line(
        linetype = "solid",
        colour = colorlist$gray,
        linewidth = 0.75 * PT_TO_MM
      ),
      panel.grid.minor = element_blank(),
      axis.title = element_blank(),
      axis.text = element_text(
        colour = colorlist$dk_gray,
        size = base_size
      ),
      strip.background = element_rect(
        fill = NA
      ),
      strip.text = element_text(
        colour = colorlist$dk_gray,
        size = base_size
      ),
      axis.ticks = element_blank(),
      panel.background = element_blank(),
      panel.border = element_rect(colour = NA),
      title = element_text(
        face = "plain",
        hjust = 0.5
      ),
      plot.title = element_text(
        hjust = 0.5,
        size = rel(1.555555)
      ),
      plot.subtitle = element_blank(),
      legend.position = "bottom",
      legend.text = element_text(
        size = base_size,
        colour = colorlist$dk_gray
      ),
      legend.title = element_blank(),
    )
}