Print

Print


Dear R community,


I am creating a map using R (prod_mapv12_fruit.png), but now I cannot figure it out how to draw the squares of the zoom-in in the middle map.

I have the coordinates of the edges for the two polygons I want to draw but cannot make them into a square. When I plot them, it only plots four dots.


# attempt one importing the data using a CSV file. In this case, I could not find a predefined function to transform the points in a polygon.

zoom_square <- read.csv("zoom_square.csv")

zoom_square_1<- zoom_square %>%
  filter(square == "A") %>%
  select(X,Y)
zoom_square_2<- zoom_square %>%
  filter(square == "B") %>%
  select(X,Y)
plot(zoom_square_1)
plot(zoom_square_2)


# attempt two: this was a suggestion I find in the internet, but could not make it work.
zoom_square_1<- rbind(c(-10.821079,-68.403542),
                                            c(-10.862918,-68.367060),
                                            c(-10.821079,-68.367060),
                                            c(-10.862918,-68.403542))
zoom_square_1_pol <- st_polygon(list(zoom_square_1))


Once the points are converted to polygons I can add the Coordinates reference system and plot them into the map.


To summarize, I want help to convert these two sets of four points into two squares (polygons) that can be used with ggplot2::geom_sf().


Best regards,


Eduardo S. Bongiolo

Masters student

School of Forest Resources and Conservation

University of Florida

This list strives to be beginner friendly. However, we still ask that you PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.