Complete the code to create a scatter plot using base R with x and y coordinates.
plot(x, y, type = [1])type = "l" which draws lines instead of points.In base R, type = "p" creates a scatter plot showing points.
Complete the code to convert Cartesian coordinates (x, y) to polar coordinates (r, theta).
r <- sqrt([1]^2 + y^2)
theta instead of x in the formula.r with the angle theta.The radius r in polar coordinates is the square root of x^2 + y^2.
Fix the error in the code to calculate the angle theta in radians from Cartesian coordinates.
theta <- atan2(y, [1])x and y in atan2.sin or cos incorrectly.The atan2 function takes y first and then x, but in R it is atan2(y, x)>. Here, to get the angle, the first argument should be y and the second x. The code has the arguments reversed, so the blank should be x to fix the order.
Fill both blanks to create a data frame with polar coordinates from Cartesian vectors x and y.
polar_coords <- data.frame(r = sqrt(x[1] + y[2]))
*2 instead of exponentiation.To calculate radius r, square both x and y using ^2, then add them.
Fill all three blanks to convert polar coordinates (r, theta) back to Cartesian coordinates (x, y).
x <- [1] * cos([2]) y <- [3] * sin(theta)
x instead of r in the formulas.r and theta in the function arguments.To convert polar to Cartesian, multiply radius r by cosine or sine of angle theta.