Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
370 views
in Technique[技术] by (71.8m points)

r - 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?

alt text

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...