I am trying to build some figures comprised to 2 right triangles arranged in a mirror-image of each other. The final plots will have unique data set, but for now I am plotting the same data. I am more familiar with (maybe spoiled by) ggplot, but I've found that it's much easier to shift the axis locations in base R. If anyone knows how to replicate these right-triangle plots in ggplot I would take that answer!
I'm having trouble with adjusting the spacing and layout. I'm not as familiar with base R plotting, sorry if these are kinda of basic.
Specifically I'd like to:
move the triangles closer together
make it so the labels are visible (and use a top label that isn't
**main**
)make the diagonal line flush with the axes
make the 'legs' of the triangles of equal length
library(cowplot) my.data <- data.frame( my.x = c(.2,.4,.6, .1), my.y = c(.3, .5, .7, .9) ) top.triangle <- function(){ plot( my.y ~ my.x, data = my.data, axes = FALSE, ylab = 'Position.2', xlab = NA, main='Position.1', xlim=c(0,1), ylim=c(0,1), xaxt="n", yaxt="n" ) axis(side = 2, las = 1, pos=0) axis(side = 3, las = 1, pos=1) abline(coef = c(0,1)) } bottom.triangle <- function() { plot( my.x ~ my.y, data = my.data , axes = FALSE, xlab = 'Position.2', ylab = 'Position.1', xlim=c(0,1), ylim=c(0,1), xaxt="n", yaxt="n" ) axis(side = 1, las = 1, pos=0) axis(4, las = 1, pos=1) #flip label to right side abline(coef = c(0,1))} plot_grid(top.triangle, bottom.triangle, rel_widths = c(.5,.5))
Thanks!