VlS
VlS

Reputation: 586

Problems with edges in R plotting

I'm having a hard time dealing with cutting edges in R plots.
The problem:
Edge problem
Code:

x <- c(130, 145, 170, 175, 180)
y <- c(0.00172225, 0.00207025, 0.002304, 0.0025, 0.002704)*1000
plot(x,y,pch=20)
fit <- lm(y~x) 
xx <- seq(120,190, length=50)
plot(x,y,xlab=(expression('U'~~'[V]')),main=expression(atop(Something)),  ylab=expression(r[1]^2~~"[mm]"),pch=19,xlim=c(120, 190),  ylim=c(0.001,0.003)*1000)
xHigh <- x+5
yHigh <- y+c(0.083, 0.091, 0.096, 0.100, 0.104)
xLow <- x-5
yLow <- y-c(0.083, 0.091, 0.096, 0.100, 0.104)
eps <- 1
eps2 <- 0.05
segments(x-eps,yLow,x+eps,yLow,col=2)
segments(x-eps,yHigh,x+eps,yHigh,col=2)
segments(xLow,y-eps2,xLow,y+eps2,col=2)
segments(xHigh,y-eps2,xHigh,y+eps2,col=2)
segments(x,yLow,x,yHigh,col=2)
segments(xLow,y,xHigh,y,col=2)
lines(xx, predict(fit, data.frame(x=xx)), col="blue")
summary(fit)

How can I resolve this problem?
Thanks in advance!

Upvotes: 1

Views: 273

Answers (1)

MrFlick
MrFlick

Reputation: 206401

Before your plot(), increase the size of your left margin:

par(mar=c(5,5,4,2)+.1)
plot(x,y,pch=20)

Base graphics simply provide a fixed number of lines on each side of the plot regardless of what you attempt to draw there.

Upvotes: 2

Related Questions