Search code examples
rggplot2scatter-plot

How to make the following plot in square dimension?


enter image description here

library(ggplot2)
if(any(Test$HQ == 1)) {
smoothScatter(Test$FREQ, Test$AF, nrpoints = 0,
xlab = "FREQ", ylab = "AF")}

I would like to know how I can output this plot in square dimension?

I have tried adj asp=1 and theme(aspect.ratio = 1), but they are not useful.


Solution

  • You can do par(pty = "s") which forces the plotting region to be square - an example with some sample data from the smoothScatter documentation:

    n <- 10000
    x1  <- matrix(rnorm(n), ncol = 2)
    x2  <- matrix(rnorm(n, mean = 3, sd = 1.5), ncol = 2)
    x   <- rbind(x1, x2)
    
    par(pty = "s")
    smoothScatter(x, nrpoints = 0)
    

    enter image description here