Hello,
I've run the code below many times, though not recently. I received this error message, but the code runs.
> Error in FUN(X[[i]], ...) : object 'fac' not found
Instead of a white background, it is grey. If fac isn't a valid fill value, what is required?
Any assistance is appreciated.
Bob
library(tidyverse)
library(sf)
world_sf = map_data("world") %>%
filter(region != "Antarctica") %>%
mutate(region=replace(region, subregion=="Alaska", "USA_Alaska")) %>%
st_as_sf(coords=c("long","lat"), crs=4326) %>%
group_by(region, group) %>% summarise(geometry=st_combine(geometry)) %>%
st_cast("POLYGON") %>% summarise(geometry=st_combine(geometry))
labs = tibble(region = c("Argentina", "Australia", "Barbados","Brazil", "England","Fiji", "France", "French Polynesia", "Ghana", "Italy","Japan", "New Zealand", "Papua New Guinea", "Peru", "Portugal", "Samoa", "Sao Tome and Principe", "Senegal", "Solomon Islands", "South Africa", "Spain", "Trinidad", "Tobago", "Turkey", "UK", "Uruguay", "USA"))
ggplot()+geom_sf(aes(fill=fac))+coord_sf(expand=FALSE)
labels_sf = st_point_on_surface(world_sf) %>% right_join(labs, by="region")
world_sf %>% mutate(fac = region %in% labs$region) %>%
ggplot()+geom_sf(aes(fill=fac))+coord_sf( expand=FALSE)+
theme(axis.title = element_blank(), legend.position = "none")+
scale_fill_manual(values=c("FALSE"=NA, "TRUE"="red"))