Theme - improper inheritance of line

Hi,

I'm trying to thicken my panel axis lines in my standard publishing graph

line = element_line(colour = "black", size = line.n.ticks),
using line inheritance, even though the left y and bottom x lines thicken tha is not the case to the rest or their tick marks.

Below my custom defined theme. ( If you don't want to install extrafonts comment 2nd line. font family is defined as arial in the following reproducible example:

Thanks!

library(tidyverse)
library(extrafont)
#> Warning: package 'tidyverse' was built under R version 3.4.4
#> Warning: package 'ggplot2' was built under R version 3.4.4
#> Warning: package 'tidyr' was built under R version 3.4.4
#> Warning: package 'readr' was built under R version 3.4.4
#> Warning: package 'purrr' was built under R version 3.4.4
#> Warning: package 'forcats' was built under R version 3.4.4
#> Warning: package 'extrafont' was built under R version 3.4.4
#> Registering fonts with R
# loadfonts()

choose.font.family = "Arial"

theme_thesis <- function (choose.font.family, axis.text, axis.title.text, strip.wrap.size  ) { 
  
  line.n.ticks = 1.0  
  theme_bw() +
    theme(panel.grid.major = element_blank(), 
          panel.grid.minor = element_blank(),
          line = element_line(colour = "black", size = line.n.ticks),
          axis.line.x = element_line(colour = "black", size = line.n.ticks),
          axis.line.x.bottom = element_line(colour = "black", size = line.n.ticks),
          axis.line.x.top = element_line(colour = "black", size = line.n.ticks),
          axis.line.y = element_line(colour = "black", size = line.n.ticks),
          axis.line.y.left = element_line(colour = "black", size = line.n.ticks),
          axis.line.y.right =element_line(colour = "black", size = line.n.ticks),
          axis.ticks = element_line(colour = "black", size = line.n.ticks),
          title = element_text(size = 20, family = choose.font.family, colour = "black"),
          plot.title = element_text(hjust = 0.5),
          legend.position="bottom",
          legend.key.width=unit(2.2, "cm"),
          legend.box= "vertical",
          legend.text=element_text(size=axis.title.text, family = choose.font.family, colour = "black"),
          legend.title = element_text(size = axis.title.text, family = choose.font.family, colour = "black"),
          axis.title.x=element_text(size = axis.title.text, family = choose.font.family, colour = "black" ),
          axis.title.y=element_text(size = axis.title.text, family = choose.font.family, colour = "black" ), 
          axis.text.x = element_text(size = axis.text, family = choose.font.family, colour = "black", margin = margin(t = 0, r = 0, b = 7, l = 0)),
          axis.text.y = element_text(size = axis.text, family = choose.font.family, colour = "black", margin = margin(t = 0, r =0, b = 0, l = 7) ),
          axis.line = element_line(colour = "black"),
          strip.text = element_text(size = strip.wrap.size, family = choose.font.family, colour = "black"))
}

# Plot a random thing

reprex.data <- data.frame(x = c(4.5, 3, 3, 3.5, 3.5, 4, 4, 0), y = c(4.5, 3, 3, 3.5, 3.5, 4, 4, 0), color = c("A", "A", "A", "A", "B", "B", "A", "A"))

ggplot(reprex.data, aes(x = x, y = y, colour = color)) +
  geom_point() +
  scale_color_viridis_d(option = "B", begin = 0.0, end = 0.85, direction = 1) +
  labs(tag = "(d)")+
  theme_thesis(choose.font.family, axis.text = 28, axis.title.text = 28, strip.wrap.size = 28)

It looks to me like the ticks are actually the same width as the ⎣ of the panel outline, but I see what you're saying re. the other two lines.

Have you tried using the new (to ggplot2 for 3.0.0) base_line_size()?

I would recommend using panel.background(element_rect()) for getting the outline you want around the entire panel. You can see, below, in the modified themes (thesis_theme1, thesis_theme2) how it changes the outline. Note that when you define the axis.line.(x or y).(direction) that gets applied when you use that particular axis.

library(tidyverse)
library(extrafont)
#> Registering fonts with R

choose.font.family = "Arial"

theme_thesis1 <- function (choose.font.family, axis.text, axis.title.text, strip.wrap.size  ) { 
  
  line.n.ticks = 1.0  
  theme_bw() +
    theme(panel.grid.major = element_blank(), 
          panel.grid.minor = element_blank(),
          line = element_line(colour = "black", size = line.n.ticks),
          panel.background = element_rect(linetype = 1, colour = "black", size = 1),
          axis.line.x = element_line(colour = "black", size = line.n.ticks),
          axis.line.x.bottom = element_line(colour = "black", size = line.n.ticks),
          axis.line.x.top = element_line(colour = "black", size = line.n.ticks),
          axis.line.y = element_line(colour = "black", size = line.n.ticks),
          axis.line.y.left = element_line(colour = "black", size = line.n.ticks),
          axis.line.y.right =element_line(colour = "black", size = line.n.ticks),
          axis.ticks = element_line(colour = "black", size = line.n.ticks),
          title = element_text(size = 20, family = choose.font.family, colour = "black"),
          plot.title = element_text(hjust = 0.5),
          legend.position="bottom",
          legend.key.width=unit(2.2, "cm"),
          legend.box= "vertical",
          legend.text=element_text(size=axis.title.text, family = choose.font.family, colour = "black"),
          legend.title = element_text(size = axis.title.text, family = choose.font.family, colour = "black"),
          axis.title.x=element_text(size = axis.title.text, family = choose.font.family, colour = "black" ),
          axis.title.y=element_text(size = axis.title.text, family = choose.font.family, colour = "black" ), 
          axis.text.x = element_text(size = axis.text, family = choose.font.family, colour = "black", margin = margin(t = 0, r = 0, b = 7, l = 0)),
          axis.text.y = element_text(size = axis.text, family = choose.font.family, colour = "black", margin = margin(t = 0, r =0, b = 0, l = 7) ),
          axis.line = element_line(colour = "black"),
          strip.text = element_text(size = strip.wrap.size, family = choose.font.family, colour = "black"))
}

theme_thesis2 <- function (choose.font.family, axis.text, axis.title.text, strip.wrap.size  ) { 
  
  line.n.ticks = 1.0  
  theme_bw() +
    theme(panel.grid.major = element_blank(), 
          panel.grid.minor = element_blank(),
          line = element_line(colour = "black", size = line.n.ticks),
          panel.background = element_rect(linetype = 1, colour = "black", size = 2),
          axis.line.x = element_line(colour = "black", size = line.n.ticks),
          axis.line.x.bottom = element_line(colour = "black", size = line.n.ticks),
          axis.line.x.top = element_line(colour = "black", size = line.n.ticks),
          axis.line.y = element_line(colour = "black", size = line.n.ticks),
          axis.line.y.left = element_line(colour = "black", size = line.n.ticks),
          axis.line.y.right =element_line(colour = "black", size = line.n.ticks),
          axis.ticks = element_line(colour = "black", size = line.n.ticks),
          title = element_text(size = 20, family = choose.font.family, colour = "black"),
          plot.title = element_text(hjust = 0.5),
          legend.position="bottom",
          legend.key.width=unit(2.2, "cm"),
          legend.box= "vertical",
          legend.text=element_text(size=axis.title.text, family = choose.font.family, colour = "black"),
          legend.title = element_text(size = axis.title.text, family = choose.font.family, colour = "black"),
          axis.title.x=element_text(size = axis.title.text, family = choose.font.family, colour = "black" ),
          axis.title.y=element_text(size = axis.title.text, family = choose.font.family, colour = "black" ), 
          axis.text.x = element_text(size = axis.text, family = choose.font.family, colour = "black", margin = margin(t = 0, r = 0, b = 7, l = 0)),
          axis.text.y = element_text(size = axis.text, family = choose.font.family, colour = "black", margin = margin(t = 0, r =0, b = 0, l = 7) ),
          axis.line = element_line(colour = "black"),
          strip.text = element_text(size = strip.wrap.size, family = choose.font.family, colour = "black"))
}

# Plot a random thing

reprex.data <- data.frame(x = c(4.5, 3, 3, 3.5, 3.5, 4, 4, 0), y = c(4.5, 3, 3, 3.5, 3.5, 4, 4, 0), color = c("A", "A", "A", "A", "B", "B", "A", "A"))

ggplot(reprex.data, aes(x = x, y = y, colour = color)) +
  geom_point() +
  scale_color_viridis_d(option = "B", begin = 0.0, end = 0.85, direction = 1) +
  labs(tag = "(d)")+
  theme_thesis1(choose.font.family, axis.text = 28, axis.title.text = 28, strip.wrap.size = 28)


ggplot(reprex.data, aes(x = x, y = y, colour = color)) +
  geom_point() +
  scale_color_viridis_d(option = "B", begin = 0.0, end = 0.85, direction = 1) +
  labs(tag = "(d)")+
  theme_thesis2(choose.font.family, axis.text = 28, axis.title.text = 28, strip.wrap.size = 28)

Created on 2018-08-14 by the reprex package (v0.2.0.9000).

1 Like

Thanks Mara !

You're a great help !!!!
Explained like that the logic behind makes sense :smiley_cat:

M.

1 Like