开发者

Drawing non-intersecting circles

I'm trying to plot two non-intersecting touching circles, but I think I'm missing something quite basic...

jpeg(file="test.jpg")
diam <- sqrt (2)
plot (c(-1,1), c(1,-1), xlim=c(-5,5), ylim=c(-5,5))

symbols (c(-1,1开发者_如何学运维), c(1,-1), circles=c(diam,diam), add=TRUE, inches=FALSE)
dev.off()

Can anyone explain to me why these circles overlap?

Drawing non-intersecting circles


Set the aspect ratio via asp:

diam <- sqrt (2)
plot (c(-1,1), c(1,-1), xlim=c(-3,3), ylim=c(-3,3), asp=1)
symbols (c(-1,1), c(1,-1), circles=c(diam,diam), add=TRUE, inches=FALSE)

Updated to add Gavin Simpson's excellent insights from the comments and chat. My answer may be correct, but Gavin provides the very helpful reasons why asp=1 works and why it isn't the default behavior. Many thanks to him.

The default plotting device settings attempt to display the data without assuming anything about the scale of the relationship between the variables. To directly quote Gavin:

The reason asp = 1 is not the default is that asp = 1 doesn't make sense for data that do not share a common unit of measurement, such as height vs weight. Why should a change of 1m in height be represented as a change of 1kg in weight?

and

As a result, distance along the x axis bears no relationship to those on the y axis. As such, what is plotted is a transformation of real circles - they really are circles, just translated because the coordinate system you are plotting them into isn't appropriate.

A way to illustrate Gavin's points would be to plot the circles on the default device (not the jpeg device), then re-size the device. You can make the circles look all sorts of weird.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜