Adjust graph made in ggplot

I would like help on two things:

1 - In the points of the graph, I would like to have the corresponding property number as well.

2 - Is it possible to bring the visualization of the points even closer?

Executable code below:

library(rgdal)
library(ggplot2)
library(sf)

temp <- tempfile()
temp2 <- tempfile()
download.file("https://geoftp.ibge.gov.br/organizacao_do_territorio/malhas_territoriais/malhas_municipais/municipio_2015/UFs/PR/pr_municipios.zip",temp)
unzip(zipfile = temp, exdir = temp2)
shp <- sf::read_sf(temp2)
shp_subset <- shp[shp$NM_MUNICIP == "CASTRO",]

#Points
Points_properties<-structure(list(Propertie = c(1,2,3,4,5), Latitude = c(-24.781624, -24.775017, -24.769196, 
-24.761741, -24.752019), Longitude = c(-49.937369, 
 -49.950576, -49.927608, -49.92762, -49.920608)), row.names = c(NA, -5L), class = c("tbl_df", "tbl", 
 "data.frame"))

ggplot() + 
  geom_sf(data = shp_subset, aes()) +
  geom_point(data = Points_properties, 
             aes(x = Longitude, y = Latitude))+
  coord_sf(xlim = c(min(Points_properties$Longitude)-0.1,
                    max(Points_properties$Longitude)+0.1),
           ylim = c(min(Points_properties$Latitude)-0.1,
                    max(Points_properties$Latitude)+0.1),
           expand = FALSE) +
  theme_void()

image

#zoomed out
#bounds_parm <- 1/5

# zoomed in
bounds_parm <- 1/50

ggplot() + 
  geom_sf(data = shp_subset, aes()) +
  geom_text(data = Points_properties, 
            aes(x = Longitude, y = Latitude,label=Propertie),
            nudge_y = .005,nudge_x=0.005) +
  geom_point(data = Points_properties, 
            aes(x = Longitude, y = Latitude)) +
  coord_sf(xlim = c(min(Points_properties$Longitude)-bounds_parm,
                    max(Points_properties$Longitude)+bounds_parm),
           ylim = c(min(Points_properties$Latitude)-bounds_parm,
                    max(Points_properties$Latitude)+bounds_parm),
           expand = FALSE) +
  theme_void()
1 Like

Thank you very much @nirgrahamuk! =)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.