Sam Miranda
Sam Miranda

Reputation: 121

Creating a blank plot with a border in r

I am trying to create a empty plot that has a green border. Essentially just creating a green box, I know how to make the plot blank but I am having trouble creating the box around the plot.

p2 <- plot(0,type='n', axes=FALSE, ann=FALSE, lty='solid', col='green')
print(p2)

Upvotes: 0

Views: 2663

Answers (3)

mutian
mutian

Reputation: 77

please try rect to control the boarder's color

plot(0,type='n',axes=FALSE,ann=FALSE)
u <- par("usr")
rect(u[1], u[3], u[2], u[4], border = "green")

Upvotes: 2

G5W
G5W

Reputation: 37661

I don't really know what you want. The solutions of @ikop and @mutian are good if you want a green line around your plot. I have the idea that you want the margins to be green. If so, here is a way to get that. Just for fun, I put a normal curve in the plot.

par(bg = 'darkgreen')
plot(0, type = 'n', axes = FALSE, ann = FALSE, 
    xlim=c(-3,3), ylim=c(0,0.5))
rect(par("usr")[1],par("usr")[3],par("usr")[2],par("usr")[4],col = "white")
curve(dnorm, xlim=c(-3,3), add=TRUE)

Normal curve with green margins

Upvotes: 0

ikop
ikop

Reputation: 1790

You can create the empty plot using

plot(0, type = 'n', axes = FALSE, ann = FALSE)

and then draw the box using the function box:

box(col = "green")

Upvotes: 3

Related Questions