Format number in ggplot map

Hi. Sorry for not share a working example. I'm doing a map in ggplot, but I don't see a way to format the label so that only two decimal places appear. See here:


In the dataframe the number seems to be formatted correctly (last column on the right):

Captura de Pantalla 2022-09-13 a las 12.52.01

Any idea how I can fix it?

This is the code:

        geom_sf(aes(fill=`relacion`), colour = "white", size = 0.07) +
        geom_sf_text(aes(label = relacion), size = 2.5, colour = "white") +
        scale_fill_distiller(palette = "Blues", name="") +

Thanks and sorry again for not provide something replicable.

You could try using the round() function in the following line. This assumes relacion is numeric.

geom_sf_text(aes(label = round(relacion, 2)), size = 2.5, colour = "white") +

Works!. Thanks a lot scottyd22.

1 Like

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.