How to use grid.show.viewport() function in R?

How to Plot the below graph using grid.show.viewport() function in R ?

Here is my code:

library(grid)
library(gridBase)

a <- viewport(x = 0.6, y = 0.6, 
           width = 1, height = 1, angle = 45)

grid.show.viewport(a)

But I am not sure how to convert npc to inches as shown in picture.

I need to plot exactly as shown in picture.

Thank you for your help!

Expected Output

Upvotes: 1

Views: 330

Answers (1)

yang
yang

Reputation: 739

You should set the unit of width and height to "inches" explicitly

library(grid)
library(gridBase)

a <- viewport(
  x = 0.6, y = 0.6, 
  width = unit(1, "inches"), height = unit(1, "inches"), 
  angle = 45
)

grid.show.viewport(a)

Created on 2020-04-16 by the reprex package (v0.3.0)

Upvotes: 2

Related Questions