出租曲线 - 从另一个维度绘制投影半径的圆圈

时间:2015-06-03 21:35:54

标签: r plot 3d

目标是在R:

中重现此Bid-Rent图表

Bid Rent Graph

挑战是画出投射的圆圈。到目前为止,我得到了:

My 2D Plot

2D部分由下面的R代码和基础R中的传统图形系统创建:

#Distance
X <- seq(0,7,1)

#Bid Rent Curves: Commercial, Industrial, Residential 
com <- -5*X + 10
ind <- -2*X + 7  
res <- -0.75*X + 4

graph <- plot(X, com, type="l", col="green", ylim=c(0,10), xlab="", ylab="", axes=FALSE)
lines(X, ind, col="red")
lines(X, res, col="blue")
abline(v=0, h=0)

segments(1,0, 1,5, lty=2)
segments(2.5,0, 2.5,2, lty=2)

title(main="Bid Rent Curves", sub="Alonso Model", 
      xlab="Distance from CBD", ylab="Rent per m2")

text(2.5,7.5, "Commercial", col="green")
text(3.5,4, "Industrial", col="red")
text(5.5,2, "Residential", col="blue")
  1. (细节:为什么曲线不尊重ylim = 0?)
  2. 如何制作投影并绘制半圆?
  3. 这不完全是3D情节。我已经研究过plot3D和rgl。我不确定从这里使用哪些包或策略。

1 个答案:

答案 0 :(得分:3)

我带你说你想要圆圈,所以你需要将绘图区域推到右上角:

outHalfCirc <- function(r,colr) {opar=par(xpd=TRUE, new=TRUE) #plot ouside plot area
   polygon(x=seq(r,-r,by=-0.1), 
          y= -sqrt(r^2 - seq(r,-r,by=-0.1)^2) , # solve r^2 = x^2 +y^2 for y
           xlim =c(0,7 ), ylim=c(0,10), col=colr,  # need xlim and ylim to match base plot ranges
           yaxs="i", yaxt="n", xaxs="i") # yaxis off; x and y axes meet at origin
  par(opar)}

然后向上和向右推动图:这将在y = 0线下方绘制一个彩色半圆(最大的第一个,因此它们重叠)。

png()  # send to image file;  not needed for testing
opar <- par(mar=c(15, 15, 2,2) ) # default units are in widths of text-"line".
# the margins start at lower, then clockwise

# run your code

outHalfCirc(5.5, "blue")
outHalfCirc(2.5, "red")
outHalfCirc(1, "green")
dev.off()  # complete image production
par(opar)  # different than the 'opar' inside the function

瞧!虽然不是真正的圆形,因为纵横比不是1.这可以修复(或者你可以设置xlim和ylim相等。 enter image description here