Search code examples
rggplot2labelclippingggtern

How to avoid clipping of labels with ggtern/ggplot2 (like xpd=TRUE)


In the ternary plot below labels outside the axes are clipped. I can't find a setting for ggtern() or ggplot2 that avoids this. For base R graphics, I would just use xpd=TRUE.

enter image description here

My data:

modes <-
structure(list(Mode = c("Literature", "Poetry", "Table", "Map", 
"Thematic map", "Graph", "Art", "Diagram", "Statistical analysis", 
"Statistical graphics"), Words = c(9L, 7L, 1L, 2L, 2L, 1L, 4L, 
2L, 6L, 8L), Numbers = c(0.5, 1, 9, 2, 8, 1, 1, 0, 15, 8), Pictures = c(1L, 
4L, 1L, 9L, 14L, 11L, 8L, 9L, 5L, 15L)), .Names = c("Mode", "Words", 
"Numbers", "Pictures"), problems = structure(list(row = 10L, 
    col = NA_character_, expected = "4 columns", actual = "5 columns", 
    file = "'modes.dat'"), .Names = c("row", "col", "expected", 
"actual", "file"), row.names = c(NA, -1L), class = c("tbl_df", 
"tbl", "data.frame")), row.names = c(NA, -10L), spec = structure(list(
    cols = structure(list(Mode = structure(list(), class = c("collector_character", 
    "collector")), Words = structure(list(), class = c("collector_integer", 
    "collector")), Numbers = structure(list(), class = c("collector_double", 
    "collector")), Pictures = structure(list(), class = c("collector_integer", 
    "collector"))), .Names = c("Mode", "Words", "Numbers", "Pictures"
    )), default = structure(list(), class = c("collector_guess", 
    "collector"))), .Names = c("cols", "default"), class = "col_spec"), class = c("tbl_df", 
"tbl", "data.frame"))

Code:

library(ggtern)

AES <- (aes(x=Numbers, y=Words, z=Pictures, label=Mode ))

ggtern(data=modes, mapping=AES) +
  geom_point(size=3, color="red") +
  geom_label(vjust = "bottom")  + theme(text = element_text(size=16))

Solution

  • I found an answer by scrolling through the theme_ suggestions in R Studio: theme_nomask() does what I want. What made this hard is that ggtern has its' own conventions for trilinear plots, different from those of ggplot2.

    ggtern(data=modes, mapping=AES) +
      geom_point(size=3, color="red") +
      geom_label(vjust = "bottom")  + 
      theme_nomask() + 
      theme(text = element_text(size=16))
    

    enter image description here