Shawn Brar
Shawn Brar

Reputation: 1420

Remove Alaska and Hawaii from US grid in geofacet

I am using this csv file for a project. It has interstate migration data for United States of America.

I am using geofacet package to plot facet_geom plot of 49 states. But this also plots Alaska and Hawaii plots. I don't want it to plot migration data for these two states, since, there is no data available in the file.

Below is my code. The plots come out properly, I only need a way to not plot the above two states.

library(data.table)
library(ggplot2)
library(geofacet)

# Load the data
data_full <- fread("data_full.csv")

# Plot the data
ggplot(data_full, aes(group = GeoName))+
    geom_line(aes(x = Year, y = In_Mig))+
    facet_geo(~ GeoName, scales = "free_y", grid = "us_state_grid1")

Upvotes: 0

Views: 235

Answers (1)

Shawn Brar
Shawn Brar

Reputation: 1420

I found the following to be an answer:-

library(data.table)
library(ggplot2)
library(geofacet)

# Load the data
data_full <- fread("data_full.csv")
my_us_grid <- us_state_grid1[c(-2, -11), ]

# Plot the data
ggplot(data_full, aes(group = GeoName))+
    geom_line(aes(x = Year, y = In_Mig))+
    facet_geo(~ GeoName, scales = "free_y", grid = my_us_grid)

Upvotes: 1

Related Questions