5
I need to make concentric circles, preferably displaced from the origin, in function plot()
to serve as a visual reference to a function. I tried the abline()
, but I was unsuccessful.
5
I need to make concentric circles, preferably displaced from the origin, in function plot()
to serve as a visual reference to a function. I tried the abline()
, but I was unsuccessful.
8
Use the command draw.circle
package plotrix
:
x <- seq(-3, 3, by=0.01)
y <- x^2
plot(y ~ x, asp=1, type="l")
library(plotrix)
draw.circle(1, 1, 1, border="red")
draw.circle(1, 1, 2, border="green")
draw.circle(1, 1, 3, border="blue")
The syntax of the command draw.circle
is quite simple:
the first argument is the coordinate of the center of the circle on the x-axis
the second argument is the coordinate of the center of the circle on the y-axis
the third argument is the radius of the circle
I altered their edge with the argument border
just to emphasize the difference between the drawn circles. By default, their border is black.
1
Building on Marcus Nunes' excellent response, you could also use the function symbols()
package graphics
.
Just remember to use add=TRUE
(for him to add the circle to a preexisting Plot) and inches = FALSE
, so that the natural range of radius of the circle, informed in circles
, is that of the axis x
.
x <- seq(-3, 3, by=0.01)
y <- x^2
plot(y ~ x, asp=1, type="l")
symbols(1, 1, circles=1, inches=FALSE, fg="red", add=TRUE)
symbols(1, 1, 2, inches=FALSE, fg="green", add=TRUE) # circles é o 3º arg
symbols(1, 1, 3, inches=FALSE, fg="blue", add=TRUE)
Abs!
Browser other questions tagged r plot
You are not signed in. Login or sign up in order to post.