palaeoverse / rphylopic

Get Silhouettes of Organisms from PhyloPic
https://rphylopic.palaeoverse.org
GNU General Public License v3.0
91 stars 9 forks source link

add_phylopic_base issue #26

Closed sckott closed 4 years ago

sckott commented 4 years ago

user asks if the line graphics::par(usr = c(0, 1, 0, 1)) https://github.com/sckott/rphylopic/blob/master/R/add_phylopic_base.r#L46 should be changed/removed

says

So, these settings limit the plotting area. I have removed it and been able to place the silhouettes in the top of the observation points.

any ideas @dill ?

dill commented 4 years ago

oh, it's been a while since I looked at this code!

I vaguely remember the usr offset thing being necessary at the time, I thought it was there so that placing the silhouettes didn't get scaled weirdly when being plotted by rasterImage (since you need to specify the corner coordinates). Does the user have a reprex?

sckott commented 4 years ago

Thanks. They just sent one:

library(rphylopic)
add_phylopic_base2 <- function (img, x = NULL, y = NULL, ysize = NULL, alpha = 0.2, 
                                   color = NULL) 
{
  img <- rphylopic:::recolor_phylopic(img, alpha, color)
  dims <- dim(img)[1:2]
  AR <- dims[1]/dims[2]
  # graphics::par(usr = c(0, 1, 0, 1))
  graphics::rasterImage(img, x - (ysize/2), y - (AR * ysize/2), 
                        x + (ysize/2), y + (AR * ysize/2), interpolate = TRUE)
}

## My sampled species
z <- image_data("7f2cbb42-12b1-4481-8ac0-705eb7363c74", size = "128")[[1]]

## Coordinates

set.seed(999)
X <- runif(10, 0, 2)
Y <- runif(10, 0, 2)

par(mfrow=c(2,1), bty="n", xlim=c(0,2))

## Plot using the original formula
plot(X, Y, pch=3, col="red", xlim=c(0,2), ylim=c(0,2), main="Original function")
add_phylopic_base(z, x = X, y = Y, ysize = 0.4) 

## Plot using the modifyed funtion. Trout appear on the top of the observations
plot(X, Y, pch=3, col="red", xlim=c(0,2), ylim=c(0,2), main="Modified function")
add_phylopic_base2(z, x = X, y = Y, ysize = 0.4) 
Screen Shot 2020-05-27 at 8 31 05 AM