How to edit the size of a ternary plot created in R?

71 views Asked by At

Thank you in advanced for reading my question, I am new to R and stackedoverflow. Please bare with me and forgive me if I have made any mistakes with the formatting of this post.

My Question: How to edit the size of a ternary plot created in R?

I found a post here where someone provided an awesome answer to someone who was looking to create a ternary plot for soil texture classification. After spending some time reading through and playing around with the code in his answer, I have also managed to create a ternary plot with the same input data.

However, despite using the same code, the plot I am receiving in R is formatted differently. By this I mean, it seams as if the size of my ternary plot is smaller than the one plotted by the author of code.

I have tried reading through the source code of the function (part of it had to be changed to improve the format of the plot, this is explained in the answer provided) to better understand it, but I cannot find anything that I understand to be responsible for size. I have attached two images below to demonstrate the difference.

My output Authors output

Below I have attached the code I am working with from the original post

area <- c('S1','S2','S3','S4','S5','S6','S7','S8')
sand <- c(76.4,56.9,61.7,64.5,71,70.1,60.5,53.7)
silt<-c(9.3,23.1,23,17.4,13.5,13.4,21.1,30.6)
clay<-c(14.3, 20,15.4,18,15.5,16.6,18.4,15.7)
my_data<-data.frame(area,sand,silt,clay)

library(plotrix)
Pracsoil <- function (soiltexture = NULL, main = "", at = seq(0.1, 0.9, by = 0.1), 
                      axis.labels = c("percent sand", "percent silt", "percent clay"), 
                      tick.labels = list(l = seq(10, 90, by = 10), r = seq(10, 
                                                                           90, by = 10), b = seq(10, 90, by = 10)), show.names = TRUE, 
                      show.lines = TRUE, col.names = "gray", bg.names = par("bg"), 
                      show.grid = FALSE, col.axis = "black", col.lines = "gray", 
                      col.grid = "gray", lty.grid = 3, show.legend = FALSE, label.points = FALSE, 
                      point.labels = NULL, col.symbols = "black", pch = par("pch"), 
                      ...) 
{
  par(xpd = TRUE)
  triax.plot(x = NULL, main = main, at = at, axis.labels = axis.labels, 
             tick.labels = tick.labels, col.axis = col.axis, show.grid = show.grid, 
             col.grid = col.grid, lty.grid = lty.grid)
  arrows(0.12, 0.41, 0.22, 0.57, length = 0.15)
  arrows(0.78, 0.57, 0.88, 0.41, length = 0.15)
  arrows(0.6, -0.1, 0.38, -0.1, length = 0.15)
  if (show.lines) {
    triax.segments <- function(h1, h3, t1, t3, col) {
      segments(1 - h1 - h3/2, h3 * sin(pi/3), 1 - t1 - 
                 t3/2, t3 * sin(pi/3), col = col)
    }
    h1 <- c(85, 70, 80, 52, 52, 50, 20, 8, 52, 45, 45, 65, 
            45, 20, 20)/100
    h3 <- c(0, 0, 20, 20, 7, 0, 0, 12, 20, 27, 27, 35, 40, 
            27, 40)/100
    t1 <- c(90, 85, 52, 52, 43, 23, 8, 0, 45, 0, 45, 45, 
            0, 20, 0)/100
    t3 <- c(10, 15, 20, 7, 7, 27, 12, 12, 27, 27, 55, 35, 
            40, 40, 60)/100
    triax.segments(h1, h3, t1, t3, col.lines)
  }
  if (show.names) {
    xpos <- c(0.5, 0.7, 0.7, 0.73, 0.73, 0.5, 0.275, 0.275, 
              0.27, 0.27, 0.25, 0.135, 0.18, 0.055, 0.49, 0.72, 
              0.9)
    ypos <- c(0.66, 0.49, 0.44, 0.36, 0.32, 0.35, 0.43, 0.39, 
              0.3, 0.26, 0.13, 0.072, 0.032, 0.024, 0.18, 0.15, 
              0.06) * sin(pi/3)
    snames <- c("clay", "silty", "clay", "silty clay", "loam", 
                "clay loam", "sandy", "clay", "sandy clay", "loam", 
                "sandy loam", "loamy", "sand", "sand", "loam", "silt loam", 
                "silt")
    text(xpos, ypos, labels=snames)
  }
  par(xpd = FALSE)
  if (is.null(soiltexture)) 
    return(NULL)
  soilpoints <- triax.points(soiltexture, show.legend = show.legend, 
                             label.points = label.points, point.labels = point.labels, 
                             col.symbols = col.symbols, pch = pch, ...)
  invisible(soilpoints)
}
Pracsoil(my_data[,2:4],col.symbols=1:8,bg.symbols=1:8,point.labels=my_data$area,pch=21,col.grid=5)
legend( x=1, 
        legend=my_data$area,
        col=1:8, 
        fill=1:8 )

I Have tried googling different characters to understand what each bit means in the code but I can only find how to change the size of the points on the plot and not the plot itself. Does anyone know how I would be able to alter the sizing to match that of the authors output?

0

There are 0 answers