Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Layering/stacking/multiple graphs on one plot using symbols

I’m trying to do this with base-r

plot(x=NA, ylim = range(smokyants$elevation_m), xlim = range(smokyants[,5:42]))
for(ii in seq(1,length(ants)))
{
  points(unlist(elevation)~unlist(ants[ii]))  
  #symbols(smokyants$elevation_m, unlist(ants[ii]), circles = unlist(ants[ii]))
}

I’d like to use symbols() the way I’m using points(), above. But when I do it’ll display multiple plots. However points() will behave how I want and will layer everything onto one graph.

Thanks in advance.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The symbols() function invokes plot() at the end, so each time it’s making a new plot. You can change this behaviour by adding par(new=TRUE) before the next plot. For example:

data(mtcars)

with(subset(mtcars, am == 1), symbols(hp, mpg, circles = wt, xlim=c(40, 350), ylim=c(10,34)))
par(new=TRUE)
with(subset(mtcars, am == 0), symbols(hp, mpg, squares = wt, xlim=c(40, 350), ylim=c(10,34),fg="red"))

Created on 2022-05-27 by the reprex package (v2.0.1)

One thing to keep in mind is that the x- and y-limits need to be the same for each plot, otherwise you will get a mismatch, potentially, between the two plots. Here’s what it would look like if we forgot to harmonize the axis limits:

data(mtcars)

with(subset(mtcars, am == 1), symbols(hp, mpg, circles = wt, ))
par(new=TRUE)
with(subset(mtcars, am == 0), symbols(hp, mpg, squares = wt, fg="red"))

Created on 2022-05-27 by the reprex package (v2.0.1)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading