I have successfully created multiple bar charts in one figure that illustrates ozone concentrations for various cities in North Carolina. Now, I want to separate certain plots from this figure so only a single plot is shown. For example, rather than the output being the figure with each plot for each city, I'd rather have the output be the single bar plot for Asheville or Cullowhee. I was told facet_wrap() can help with this but have had no luck. Any help would be much appreciated!
### Libraries Used
library(httr)
library(jsonlite)
library(ggplot2)
library(dplyr)
### Sample Data Set
data.frame(stringsAsFactors=FALSE,
data_cbsa = c("Asheville, NC", "Asheville, NC", "Asheville, NC",
"Asheville, NC", "Asheville, NC", "Asheville, NC",
"Asheville, NC", "Asheville, NC", "Asheville, NC",
"Asheville, NC", "Asheville, NC", "Asheville, NC",
"Charlotte-Concord-Gastonia, NC-SC",
"Charlotte-Concord-Gastonia, NC-SC", "Charlotte-Concord-Gastonia, NC-SC",
"Charlotte-Concord-Gastonia, NC-SC",
"Charlotte-Concord-Gastonia, NC-SC", "Charlotte-Concord-Gastonia,
NC-SC", "Charlotte-Concord-Gastonia, NC-SC",
"Charlotte-Concord-Gastonia, NC-SC",
"Charlotte-Concord-Gastonia, NC-SC", "Charlotte-Concord-Gastonia, NC-SC",
"Charlotte-Concord-Gastonia, NC-SC",
"Charlotte-Concord-Gastonia, NC-SC", "Cullowhee, NC", "Cullowhee, NC",
"Cullowhee, NC", "Cullowhee, NC", "Cullowhee, NC",
"Cullowhee, NC", "Cullowhee, NC", "Cullowhee, NC",
"Cullowhee, NC", "Cullowhee, NC", "Cullowhee, NC",
"Durham-Chapel Hill, NC", "Durham-Chapel Hill, NC",
"Durham-Chapel Hill, NC", "Durham-Chapel Hill, NC",
"Durham-Chapel Hill, NC", "Durham-Chapel Hill, NC",
"Durham-Chapel Hill, NC", "Durham-Chapel Hill, NC",
"Durham-Chapel Hill, NC", "Durham-Chapel Hill, NC",
"Durham-Chapel Hill, NC", "Durham-Chapel Hill, NC", "Fayetteville,
NC", "Fayetteville, NC", "Fayetteville, NC",
"Fayetteville, NC", "Fayetteville, NC", "Fayetteville, NC",
"Fayetteville, NC", "Fayetteville, NC", "Fayetteville,
NC", "Fayetteville, NC", "Fayetteville, NC",
"Fayetteville, NC", "Greensboro-High Point, NC",
"Greensboro-High Point, NC", "Greensboro-High Point, NC",
"Greensboro-High Point, NC", "Greensboro-High Point, NC",
"Greensboro-High Point, NC", "Greensboro-High Point,
NC", "Greensboro-High Point, NC",
"Greensboro-High Point, NC", "Greensboro-High Point, NC",
"Greensboro-High Point, NC", "Greensboro-High Point, NC",
"Greenville, NC", "Greenville, NC", "Greenville, NC",
"Greenville, NC", "Greenville, NC", "Greenville, NC",
"Greenville, NC", "Greenville, NC", "Greenville, NC",
"Greenville, NC", "Greenville, NC", "Greenville, NC",
"Hickory-Lenoir-Morganton, NC", "Hickory-Lenoir-Morganton,
NC", "Hickory-Lenoir-Morganton, NC",
"Hickory-Lenoir-Morganton, NC", "Hickory-Lenoir-Morganton, NC",
"Hickory-Lenoir-Morganton, NC", "Hickory-Lenoir-Morganton,
NC", "Hickory-Lenoir-Morganton, NC",
"Hickory-Lenoir-Morganton, NC", "Hickory-Lenoir-Morganton, NC",
"Hickory-Lenoir-Morganton, NC",
"Hickory-Lenoir-Morganton, NC", "Kinston, NC", "Kinston, NC", "Kinston, NC",
"Kinston, NC", "Kinston, NC", "Kinston, NC", "Kinston,
NC", "Kinston, NC", "Kinston, NC", "Kinston, NC",
"Kinston, NC", "Kinston, NC", "Morehead City, NC",
"Morehead City, NC", "Morehead City, NC", "Morehead City,
NC", "Morehead City, NC", "Morehead City, NC",
"Morehead City, NC", "Morehead City, NC", "Morehead City,
NC", "Morehead City, NC", "Morehead City, NC",
"Morehead City, NC", "Oxford, NC", "Oxford, NC", "Oxford,
NC", "Oxford, NC", "Oxford, NC", "Oxford, NC",
"Oxford, NC", "Oxford, NC", "Oxford, NC", "Oxford, NC",
"Oxford, NC", "Oxford, NC", "Raleigh, NC", "Raleigh, NC",
"Raleigh, NC", "Raleigh, NC", "Raleigh, NC",
"Raleigh, NC", "Raleigh, NC", "Raleigh, NC", "Raleigh, NC",
"Raleigh, NC", "Raleigh, NC", "Raleigh, NC",
"Rocky Mount, NC", "Rocky Mount, NC", "Rocky Mount, NC",
"Rocky Mount, NC", "Rocky Mount, NC", "Rocky Mount, NC",
"Rocky Mount, NC", "Rocky Mount, NC", "Rocky Mount,
NC", "Rocky Mount, NC", "Rocky Mount, NC",
"Rocky Mount, NC", "Sanford, NC", "Sanford, NC", "Sanford, NC",
"Sanford, NC", "Sanford, NC", "Wilmington, NC",
"Wilmington, NC", "Wilmington, NC", "Wilmington, NC",
"Wilmington, NC", "Wilmington, NC", "Wilmington, NC",
"Wilmington, NC", "Wilmington, NC", "Wilmington, NC",
"Wilmington, NC", "Wilmington, NC", "Winston-Salem,
NC", "Winston-Salem, NC", "Winston-Salem, NC",
"Winston-Salem, NC", "Winston-Salem, NC", "Winston-Salem, NC",
"Winston-Salem, NC", "Winston-Salem, NC",
"Winston-Salem, NC", "Winston-Salem, NC", "Winston-Salem, NC"),
data_year = c(2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014,
2015, 2016, 2017, 2018, 2007, 2008, 2009, 2010,
2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2007,
2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
2018, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014,
2015, 2016, 2017, 2018, 2007, 2008, 2009, 2010, 2011,
2012, 2013, 2014, 2015, 2016, 2017, 2018, 2007,
2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016,
2017, 2018, 2007, 2008, 2009, 2010, 2011, 2012, 2013,
2014, 2015, 2016, 2017, 2018, 2007, 2008, 2009, 2010,
2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2007,
2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016,
2017, 2018, 2007, 2008, 2009, 2010, 2011, 2012,
2013, 2014, 2015, 2016, 2017, 2018, 2007, 2008, 2009,
2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018,
2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015,
2016, 2017, 2018, 2007, 2008, 2009, 2010, 2011, 2012,
2013, 2014, 2015, 2016, 2017, 2018, 2014, 2015, 2016,
2017, 2018, 2007, 2008, 2009, 2010, 2011, 2012,
2013, 2014, 2015, 2016, 2017, 2018, 2007, 2008, 2009,
2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017),
highest_4th_max_cbsa = c(0.077, 0.08, 0.066, 0.074, 0.067, 0.07, 0.064,
0.067, 0.066, 0.067, 0.063, 0.065, 0.096, 0.093,
0.073, 0.082, 0.088, 0.085, 0.067, 0.068, 0.073, 0.074,
0.068, 0.07, 0.08, 0.063, 0.069, 0.068, 0.069,
0.067, 0.068, 0.065, 0.069, 0.064, 0.065, 0.08, 0.078,
0.066, 0.074, 0.072, 0.076, 0.062, 0.065, 0.061, 0.063,
0.061, 0.063, 0.082, 0.075, 0.068, 0.073, 0.076,
0.069, 0.062, 0.066, 0.062, 0.064, 0.063, 0.064, 0.086,
0.084, 0.072, 0.076, 0.076, 0.078, 0.062, 0.065,
0.066, 0.068, 0.065, 0.067, 0.079, 0.077, 0.066, 0.069,
0.074, 0.071, 0.063, 0.063, 0.06, 0.065, 0.061, 0.066,
0.081, 0.076, 0.064, 0.071, 0.067, 0.067, 0.063,
0.064, 0.065, 0.066, 0.063, 0.065, 0.077, 0.074, 0.064,
0.069, 0.069, 0.069, 0.063, 0.065, 0.062, 0.063,
0.062, 0.064, 0.07, 0.059, 0.062, 0.065, 0.063, 0.058,
0.062, 0.062, 0.058, 0.06, 0.057, 0.06, 0.083, 0.081,
0.07, 0.074, 0.072, 0.072, 0.063, 0.065, 0.063, 0.065,
0.065, 0.065, 0.084, 0.078, 0.069, 0.074, 0.078,
0.075, 0.062, 0.064, 0.065, 0.069, 0.066, 0.063, 0.08,
0.075, 0.066, 0.072, 0.072, 0.071, 0.064, 0.062, 0.061,
0.064, 0.061, 0.062, 0.064, 0.06, 0.064, 0.059,
0.06, 0.071, 0.066, 0.06, 0.062, 0.064, 0.064, 0.064,
0.063, 0.057, 0.06, 0.057, 0.062, 0.085, 0.081, 0.068,
0.081, 0.076, 0.079, 0.066, 0.067, 0.07, 0.07, 0.066)
)
### Minimal Runnable Code
ggplot(o3_cbsa_annual_2015_std_summary,
aes(x=data_year,y=highest_4th_max_cbsa)) +
geom_col(position = "dodge", fill = 'red') +
facet_wrap(~data_cbsa, 'Asheville, NC')
Warning messages:
1: Coercing `nrow` to be an integer.
2: In sanitise_dim(nrow) : NAs introduced by coercion
3: `nrow` is missing or less than 1 and will be treated as NULL.