3

This question is very similar to r - degree symbol incorrect in map axis labels, though that was on a Linux machine. I'm experiencing a similar issue on Windows 10.

library(sf)                                            
library(ggplot2) 
                                      
nc = st_read(system.file("shape/nc.shp", package="sf"))

ggplot() +                                             
  geom_sf(data = nc)

Produces the following: v

I expect the degree symbols to render properly, and suspect this has something to do with Windoze fonts. However, I'm not sure how best to address the matter.

The answer to the other question involves editing a /etc/fonts/local.conf file. I find several of these files on the system, one of them is in the R directory but for an older version of R. I'm a bit weary of editing random config files without understanding what I'm doing. Any insight would be much appreciated.

ncraig
  • 783
  • 1
  • 10
  • 23

1 Answers1

0

My solution is and example is ad seq in xlab and ylabs

perurna = rnaturalearth::ne_countries(country = 'PERU',returnclass = 'sf')
perurna

xlabs = seq(-81,-68, 2)
ylabs = seq(-18, -0,3)
perurna

  ggplot(data =et1)+
  geom_point(aes(x = Longitud, y = Latitud,color=value),size=2) +
  geom_sf(fill='transparent',data=perurna, colour = "transparent")+
  scale_x_continuous(breaks = xlabs, labels = paste0(xlabs,'°W')) +
  scale_y_continuous(breaks = ylabs, labels = paste0(ylabs,'°S')) +
  geom_polygon(data=shp2, aes(x=long, y=lat, group=group),color = "black",fill=NA, size = .1)+
  scale_color_gradientn(colours = rainbow(5),breaks=seq(-1,1,0.2),limits=c(-1,1))+
  geom_point(aes(x = Longitud, y = Latitud),colour = "black",alpha = 0.3,shape=21,size=2) +
  labs(x = "LON",y= "LAT",color = "PP CORR")+
  theme_cowplot()+
  ggtitle("Correlacion Precipitacion") + 
  theme(panel.grid.major = element_line(color='black',linetype = 'dashed',size = 0.1),
        panel.grid.minor = element_blank(),
        panel.ontop = TRUE,
        panel.background = element_rect(fill = NA,color='black'),
        plot.title = element_text(hjust = 0.5))+
  facet_wrap(~ variable)

enter image description here

zhangxaochen
  • 32,744
  • 15
  • 77
  • 108
  • 3
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 13 '21 at 05:38