Question

In: Computer Science

Hey anyone good with R studio? How do you create a square shape with R code...

Hey anyone good with R studio?

How do you create a square shape with R code by using plot() and lines()

please show your code !

Solutions

Expert Solution

In this example, we are going to draw a simple square polygon to an empty R plot. Let’s first create an empty plot:

plot(1, 1, col = "white", xlab = "X", ylab = "Y")            # Draw empty plot

To this plot, we can draw a polygon with the following R code:

polygon(x = c(0.7, 1.3, 1.2, 0.8),                           # X-Coordinates of polygon
        y = c(0.6, 0.8, 1.4, 1),                             # Y-Coordinates of polygon
        col = "#1b98e0")                                     # Color of polygon

It will look like this

As you can see, the previous polygon() R code consists of three different components:

  • x: Here we specify the x-coordinates of each corner of the square polygon.
  • y: Here we specify the y-coordinates of each corner of the square polygon.
  • color: Here we specify the color of the polygon.

For the second example, I’m using exactly the same code as in Example 1, but this time I’m modifying the border color of the polygon. Let’s begin again with an empty graph…

plot(1, 1, col = "white", xlab = "X", ylab = "Y")            # Draw empty plot

…and then let’s draw a thick red border around the polygon:

polygon(x = c(0.7, 1.3, 1.2, 0.8),                           # X-Coordinates of polygon
        y = c(0.6, 0.8, 1.4, 1),                             # Y-Coordinates of polygon
        col = "#1b98e0",                                     # Color of polygon
        border = "red",                                      # Color of polygon border
        lwd = 5)                                             # Thickness of border

We used two further options within the R polygon function:

  • border: Here we specify the border color.
  • lwd: Here we specify the thickness of the border.

That’s it with the square polygon examples.


Related Solutions

Does anyone know the code to use in R programming to create a scatter plot?
Does anyone know the code to use in R programming to create a scatter plot?
Does anyone know the code to use in R programming to create a box plot?
Does anyone know the code to use in R programming to create a box plot?
How do you plot continuous versus category in r studio
How do you plot continuous versus category in r studio
how do you test for regression in R studio with variables x and y
how do you test for regression in R studio with variables x and y
In r studio, how do you find significant variables that differ between two datasets of the...
In r studio, how do you find significant variables that differ between two datasets of the same variables?
In R/ R Studio, what code would I enter to find the answers to these questions?...
In R/ R Studio, what code would I enter to find the answers to these questions? What is the code to find the descriptive/ summary statistics of all variables in a data set and how do i find the mean values? What is the code to measure the skewness measure of delta time for all of all the values in the data set? What is the code to draw a histogram and q-q plot of the natural log of a...
1. Use R Studio: Include R Code A survey is taken of 250 students, and a...
1. Use R Studio: Include R Code A survey is taken of 250 students, and a phat of 0.48 is found. The same survey is repeated with 1000 students, and the same phat value is found. Compare the two 95% confidence intervals. What is the relationship between them? Is the margin of error for the second one four times smaller? If not, how much smaller is it?
Using R Studio Use the two iid samples. (You can copy and paste the code into...
Using R Studio Use the two iid samples. (You can copy and paste the code into R). They both come from the same normal distribution. X = c(-0.06, 1.930, 0.608 -0.133,0.657, -1.284, 0.166, 0.963, 0.719, -0.896) Y = c(0.396, 0.687, 0.809, 0.939, -0.381, -0.042, -1.529, -0.543, 0.758, -2.574, -0.160, -0.713, 0.311, -0.515, -2.332, -0.844, -0.942, 0.053, 0.066, 0.942, -0.861, -0.186, -0.947, -0.110, 0.634, 2.357, 0.201, -0.428, -1.661, 0.395) (a) Report 95% confidence interval for the mean of X. Should we...
How do I do this in R Studio? 1 Students who performed poorly on a City...
How do I do this in R Studio? 1 Students who performed poorly on a City of New York Skills Assessment Test were enrolled in a summer math program. Scores of 10 students before and after the summer program were recorded. They were: Before = 18,18,21,18,18,20,23,23,21,17 After = 24,25,33,29,33,36,34,36,34,27 (Scores for individual students are in the same order in each list.) Did the NYC summer math program improve student performance significantly? 8. How many points did student scores improve on...
Does anyone know how to import data from Microsoft Excel code to use in R programming...
Does anyone know how to import data from Microsoft Excel code to use in R programming ?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT