Error in theme_map() : could not find function "theme_map"

So I am following an example in the "Data Visualization - A practical introduction by Kieran Healy" where I have to create a US map to visualize the data of the 2016 US election. I am just redoing what are shown in the book and not creating anything new yet. However, there is a particular problem about the theme_map() function where Rstudio keeps saying that it could not find this function. I am running the latest R version for Windows (4.0.3) and have even tried install/reinstall "ggplot2", "mapproj", etc., yet this problem still persists. Does anyone know why?

p0 <- ggplot(data = us_states_elec,
             mapping = aes(x = long, y = lat,
                           group = group, fill = party))
p1 <- p0 + geom_polygon(color = "gray90", size = 0.1) +
    coord_map(projection = "albers", lat0 = 39, lat1 = 45) 
p2 <- p1 + scale_fill_manual(values = party_colors) +
    labs(title = "Election Results 2016", fill = NULL)
p2 + theme_map() 

theme_map is in the ggthemes package, so you need to run library(ggthemes) to load that package before running the plot code.

1 Like

There is also a theme_map() function on the cowplot package, you better double-check the instructions to find out which one you need to use.

2 Likes

Confirmed! I had the same issue and library (cowplot) resolved it.
Thanks!

This topic was automatically closed 21 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.