rggplot2ggtern

Increase arrow thickness in ternary plot [ggtern]


Here's some example code.

library(ggtern)
# Based of random data.
DATA <- data.frame(A = runif(100), B = runif(100), C = runif(100))
plot <- ggtern(data = DATA, 
               mapping = aes(x = A, y = B, z = C)) + 
        geom_point() + ggtern::theme_bw(base_size = 30) + theme_arrowlarge()
plot

enter image description here

How do I increase the thickness of the arrows and the arrowheads? They are just way too thin once I start increasing the size of labels.

Also, how do I use the parameter base_size with the ggtern themes? Because it seems it only works with certain themes, I am not sure if I am using this correctly if I want to scale everything up, including the arrows.


Solution

  • To change the line thickness of the arrows, you can access tern.axis.arrow through the theme() function. Then change the size of element_line() to be whatever you'd prefer.

    library(ggtern)
    # Based of random data.
    DATA <- data.frame(A = runif(100), B = runif(100), C = runif(100))
    ggtern(data = DATA, 
                   mapping = aes(x = A, y = B, z = C)) + 
      geom_point() + 
      ggtern::theme_bw(base_size = 30) + 
      theme_arrowlarge() +
      theme(tern.axis.arrow = element_line(size = 3))
    
    

    If you'd like to modify the arrow options directly, you can see from the code behind the ggtern::theme_bw function that the lineend calls from a global option called tern.arrow.

    function (base_size = 12, base_family = "") 
    {
        base = ggplot2::theme_bw(base_size, base_family)
        theme_ggtern(base_size, base_family) %+replace% base %+replace% 
            theme(tern.plot.background = element_rect(size = NA, 
                color = NA), tern.axis.line = element_line(color = base$panel.border$colour), 
                tern.axis.arrow = element_line(color = base$panel.border$colour, 
                    lineend = getOption("tern.arrow")))
    }
    <bytecode: 0x7fb23868a558>
    <environment: namespace:ggtern>
    

    So, you can play around with the options for the arrow as needed to adjust the arrow type, size, etc. For example, here we change the arrow head to be 0.75 cm and the line thickness to be size 3.

    DATA <- data.frame(A = runif(100), B = runif(100), C = runif(100))
    options(tern.arrow = arrow(type = "open", length = unit(.75, "cm")))
    ggtern(data = DATA, 
                   mapping = aes(x = A, y = B, z = C)) + 
      geom_point() + 
      ggtern::theme_bw(base_size = 30) + 
      theme_arrowlarge() +
      theme(tern.axis.arrow = element_line(size = 3))
    

    This produces a figure with thicker lines and bigger arrows.