How do I find the average x in ANY plot in R using grconvertX?

I am wondering what ANY plot is drawn using BASE R (i.e. without any layout()

or mfcol()

or mfrow()

) (see example below), how can one find the "X" coordinate of a point that would always be exactly in the middle of this plot (suppose that "Y" for a point is arbitrary)?

I think it's grconvertX

intended for this, but I'm not sure how it works (I appreciate a good explanation in grconvertX

) as it has a lot of customization (see below).

plot(1, t = "n", log = "x")

mean( grconvertX(0:1, "user") )
mean( grconvertX(0:1, "nic")  )
mean( grconvertX(0:1, "nfc")  )
mean( grconvertX(0:1, "ndc")  )
mean( grconvertX(0:1, "npc")  )
mean( grconvertX(0:1, "device") )

      

+3


source to share


1 answer


You can par("usr")

. Read more in ?par

. Since you are using log = x

, you need to raise par("usr")[1:2]

on 10

.



plot(1, type = "n", log = "x")
points(x = 10^mean(par("usr")[1:2]), y = mean(par("usr")[3:4]), pch = 19)

      

+1


source







All Articles