Home > OS >  How can I get rid of overlapping issue in ggplot?
How can I get rid of overlapping issue in ggplot?

Time:04-19

enter image description hereHi all, I have this graph (above) but I recognize it is a bit hard to interpret/visualize with ease. There is a lot of overlapping going on and I want to make it easier for the end-user to interpret. Appreciate any advice regarding this.

Here is my dataset:

> dput(LD)
structure(list(Ctyname = c("Fairfield County", "Hartford County", 
"Litchfield County", "Middlesex County", "New Haven County", 
"New London County", "Tolland County", "Windham County", "Connecticut", 
"Kent County", "New Castle County", "Sussex County", "Delaware", 
"Androscoggin County", "Aroostook County", "Cumberland County", 
"Franklin County", "Hancock County", "Kennebec County", "Knox County", 
"Lincoln County", "Oxford County", "Penobscot County", "Piscataquis County", 
"Sagadahoc County", "Somerset County", "Waldo County", "Washington County", 
"York County", "Maine", "Allegany County", "Anne Arundel County", 
"Baltimore County", "Calvert County", "Caroline County", "Carroll County", 
"Cecil County", "Charles County", "Dorchester County", "Frederick County", 
"Garrett County", "Harford County", "Howard County", "Kent County", 
"Montgomery County", "Prince George's County", "Queen Anne's County", 
"St. Mary's County", "Somerset County", "Talbot County", "Washington County", 
"Wicomico County", "Worcester County", "Baltimore city", "Maryland", 
"Barnstable County", "Berkshire County", "Bristol County", "Dukes County", 
"Essex County", "Franklin County", "Hampden County", "Hampshire County", 
"Middlesex County", "Nantucket County", "Norfolk County", "Plymouth County", 
"Suffolk County", "Worcester County", "Massachusetts", "Belknap County", 
"Carroll County", "Cheshire County", "Coos County", "Grafton County", 
"Hillsborough County", "Merrimack County", "Rockingham County", 
"Strafford County", "Sullivan County", "New Hampshire", "Atlantic County", 
"Bergen County", "Burlington County", "Camden County", "Cape May County", 
"Cumberland County", "Essex County", "Gloucester County", "Hudson County", 
"Hunterdon County", "Mercer County", "Middlesex County", "Monmouth County", 
"Morris County", "Ocean County", "Passaic County", "Salem County", 
"Somerset County", "Sussex County", "Union County", "Warren County", 
"New Jersey", "Albany County", "Allegany County", "Bronx County", 
"Broome County", "Cattaraugus County", "Cayuga County", "Chautauqua County", 
"Chemung County", "Chenango County", "Clinton County", "Columbia County", 
"Cortland County", "Delaware County", "Dutchess County", "Erie County", 
"Essex County", "Franklin County", "Fulton County", "Genesee County", 
"Greene County", "Hamilton County", "Herkimer County", "Jefferson County", 
"Kings County", "Lewis County", "Livingston County", "Madison County", 
"Monroe County", "Montgomery County", "Nassau County", "New York County", 
"Niagara County", "Oneida County", "Onondaga County", "Ontario County", 
"Orange County", "Orleans County", "Oswego County", "Otsego County", 
"Putnam County", "Queens County", "Rensselaer County", "Richmond County", 
"Rockland County", "St. Lawrence County", "Saratoga County", 
"Schenectady County", "Schoharie County", "Schuyler County", 
"Seneca County", "Steuben County", "Suffolk County", "Sullivan County", 
"Tioga County", "Tompkins County", "Ulster County", "Warren County", 
"Washington County", "Wayne County", "Westchester County", "Wyoming County", 
"Yates County", "New York", "Adams County", "Allegheny County", 
"Armstrong County", "Beaver County", "Bedford County", "Berks County", 
"Blair County", "Bradford County", "Bucks County", "Butler County", 
"Cambria County", "Cameron County", "Carbon County", "Centre County", 
"Chester County", "Clarion County", "Clearfield County", "Clinton County", 
"Columbia County", "Crawford County", "Cumberland County", "Dauphin County", 
"Delaware County", "Elk County", "Erie County", "Fayette County", 
"Forest County", "Franklin County", "Fulton County", "Greene County", 
"Huntingdon County", "Indiana County", "Jefferson County", "Juniata County", 
"Lackawanna County", "Lancaster County", "Lawrence County", "Lebanon County", 
"Lehigh County", "Luzerne County", "Lycoming County", "McKean County", 
"Mercer County", "Mifflin County", "Monroe County", "Montgomery County", 
"Montour County", "Northampton County", "Northumberland County", 
"Perry County", "Philadelphia County", "Pike County", "Potter County", 
"Schuylkill County", "Snyder County", "Somerset County", "Sullivan County", 
"Susquehanna County", "Tioga County", "Union County", "Venango County", 
"Warren County", "Washington County", "Wayne County", "Westmoreland County", 
"Wyoming County", "York County", "Pennsylvania", "Bristol County", 
"Kent County", "Newport County", "Providence County", "Washington County", 
"Rhode Island", "Addison County", "Bennington County", "Caledonia County", 
"Chittenden County", "Essex County", "Franklin County", "Grand Isle County", 
"Lamoille County", "Orange County", "Orleans County", "Rutland County", 
"Washington County", "Windham County", "Windsor County", "Vermont", 
"Adams County", "Ashland County", "Barron County", "Bayfield County", 
"Brown County", "Buffalo County", "Burnett County", "Calumet County", 
"Chippewa County", "Clark County", "Columbia County", "Crawford County", 
"Dane County", "Dodge County", "Door County", "Douglas County", 
"Dunn County", "Eau Claire County", "Florence County", "Fond du Lac County", 
"Forest County", "Grant County", "Green County", "Green Lake County", 
"Iowa County", "Iron County", "Jackson County", "Jefferson County", 
"Juneau County", "Kenosha County", "Kewaunee County", "La Crosse County", 
"Lafayette County", "Langlade County", "Lincoln County", "Manitowoc County", 
"Marathon County", "Marinette County", "Marquette County", "Menominee County", 
"Milwaukee County", "Monroe County", "Oconto County", "Oneida County", 
"Outagamie County", "Ozaukee County", "Pepin County", "Pierce County", 
"Polk County", "Portage County", "Price County", "Racine County", 
"Richland County", "Rock County", "Rusk County", "St. Croix County", 
"Sauk County", "Sawyer County", "Shawano County", "Sheboygan County", 
"Taylor County", "Trempealeau County", "Vernon County", "Vilas County", 
"Walworth County", "Washburn County", "Washington County", "Waukesha County", 
"Waupaca County", "Waushara County", "Winnebago County", "Wood County", 
"Wisconsin"), Stname = c("Connecticut", "Connecticut", "Connecticut", 
"Connecticut", "Connecticut", "Connecticut", "Connecticut", "Connecticut", 
"Connecticut", "Delaware", "Delaware", "Delaware", "Delaware", 
"Maine", "Maine", "Maine", "Maine", "Maine", "Maine", "Maine", 
"Maine", "Maine", "Maine", "Maine", "Maine", "Maine", "Maine", 
"Maine", "Maine", "Maine", "Maryland", "Maryland", "Maryland", 
"Maryland", "Maryland", "Maryland", "Maryland", "Maryland", "Maryland", 
"Maryland", "Maryland", "Maryland", "Maryland", "Maryland", "Maryland", 
"Maryland", "Maryland", "Maryland", "Maryland", "Maryland", "Maryland", 
"Maryland", "Maryland", "Maryland", "Maryland", "Massachusetts", 
"Massachusetts", "Massachusetts", "Massachusetts", "Massachusetts", 
"Massachusetts", "Massachusetts", "Massachusetts", "Massachusetts", 
"Massachusetts", "Massachusetts", "Massachusetts", "Massachusetts", 
"Massachusetts", "Massachusetts", "New Hampshire", "New Hampshire", 
"New Hampshire", "New Hampshire", "New Hampshire", "New Hampshire", 
"New Hampshire", "New Hampshire", "New Hampshire", "New Hampshire", 
"New Hampshire", "New Jersey", "New Jersey", "New Jersey", "New Jersey", 
"New Jersey", "New Jersey", "New Jersey", "New Jersey", "New Jersey", 
"New Jersey", "New Jersey", "New Jersey", "New Jersey", "New Jersey", 
"New Jersey", "New Jersey", "New Jersey", "New Jersey", "New Jersey", 
"New Jersey", "New Jersey", "New Jersey", "New York", "New York", 
"New York", "New York", "New York", "New York", "New York", "New York", 
"New York", "New York", "New York", "New York", "New York", "New York", 
"New York", "New York", "New York", "New York", "New York", "New York", 
"New York", "New York", "New York", "New York", "New York", "New York", 
"New York", "New York", "New York", "New York", "New York", "New York", 
"New York", "New York", "New York", "New York", "New York", "New York", 
"New York", "New York", "New York", "New York", "New York", "New York", 
"New York", "New York", "New York", "New York", "New York", "New York", 
"New York", "New York", "New York", "New York", "New York", "New York", 
"New York", "New York", "New York", "New York", "New York", "New York", 
"New York", "Pennsylvania", "Pennsylvania", "Pennsylvania", "Pennsylvania", 
"Pennsylvania", "Pennsylvania", "Pennsylvania", "Pennsylvania", 
"Pennsylvania", "Pennsylvania", "Pennsylvania", "Pennsylvania", 
"Pennsylvania", "Pennsylvania", "Pennsylvania", "Pennsylvania", 
"Pennsylvania", "Pennsylvania", "Pennsylvania", "Pennsylvania", 
"Pennsylvania", "Pennsylvania", "Pennsylvania", "Pennsylvania", 
"Pennsylvania", "Pennsylvania", "Pennsylvania", "Pennsylvania", 
"Pennsylvania", "Pennsylvania", "Pennsylvania", "Pennsylvania", 
"Pennsylvania", "Pennsylvania", "Pennsylvania", "Pennsylvania", 
"Pennsylvania", "Pennsylvania", "Pennsylvania", "Pennsylvania", 
"Pennsylvania", "Pennsylvania", "Pennsylvania", "Pennsylvania", 
"Pennsylvania", "Pennsylvania", "Pennsylvania", "Pennsylvania", 
"Pennsylvania", "Pennsylvania", "Pennsylvania", "Pennsylvania", 
"Pennsylvania", "Pennsylvania", "Pennsylvania", "Pennsylvania", 
"Pennsylvania", "Pennsylvania", "Pennsylvania", "Pennsylvania", 
"Pennsylvania", "Pennsylvania", "Pennsylvania", "Pennsylvania", 
"Pennsylvania", "Pennsylvania", "Pennsylvania", "Pennsylvania", 
"Rhode Island", "Rhode Island", "Rhode Island", "Rhode Island", 
"Rhode Island", "Rhode Island", "Vermont", "Vermont", "Vermont", 
"Vermont", "Vermont", "Vermont", "Vermont", "Vermont", "Vermont", 
"Vermont", "Vermont", "Vermont", "Vermont", "Vermont", "Vermont", 
"Wisconsin", "Wisconsin", "Wisconsin", "Wisconsin", "Wisconsin", 
"Wisconsin", "Wisconsin", "Wisconsin", "Wisconsin", "Wisconsin", 
"Wisconsin", "Wisconsin", "Wisconsin", "Wisconsin", "Wisconsin", 
"Wisconsin", "Wisconsin", "Wisconsin", "Wisconsin", "Wisconsin", 
"Wisconsin", "Wisconsin", "Wisconsin", "Wisconsin", "Wisconsin", 
"Wisconsin", "Wisconsin", "Wisconsin", "Wisconsin", "Wisconsin", 
"Wisconsin", "Wisconsin", "Wisconsin", "Wisconsin", "Wisconsin", 
"Wisconsin", "Wisconsin", "Wisconsin", "Wisconsin", "Wisconsin", 
"Wisconsin", "Wisconsin", "Wisconsin", "Wisconsin", "Wisconsin", 
"Wisconsin", "Wisconsin", "Wisconsin", "Wisconsin", "Wisconsin", 
"Wisconsin", "Wisconsin", "Wisconsin", "Wisconsin", "Wisconsin", 
"Wisconsin", "Wisconsin", "Wisconsin", "Wisconsin", "Wisconsin", 
"Wisconsin", "Wisconsin", "Wisconsin", "Wisconsin", "Wisconsin", 
"Wisconsin", "Wisconsin", "Wisconsin", "Wisconsin", "Wisconsin", 
"Wisconsin", "Wisconsin", "Wisconsin"), Cases2019 = c(194, 132, 
116, 119, 211, 254, 107, 93, 7, 79, 407, 130, 25, 98, 2, 354, 
39, 192, 277, 232, 132, 88, 111, 4, 83, 68, 143, 31, 312, 1, 
70, 110, 138, 49, 12, 169, 61, 12, 4, 126, 26, 140, 115, 20, 
134, 22, 44, 37, 6, 19, 36, 12, 14, 41, 0, 1, 0, 0, 1, 0, 0, 
0, 0, 0, 1, 2, 1, 0, 1, 0, 72, 96, 75, 10, 119, 419, 250, 415, 
159, 74, 21, 94, 196, 234, 80, 26, 63, 113, 140, 24, 339, 186, 
171, 368, 425, 225, 132, 46, 200, 251, 62, 242, 2, 143, 14, 25, 
76, 51, 36, 31, 8, 29, 61, 188, 92, 50, 275, 31, 36, 68, 78, 
14, 83, 2, 46, 31, 281, 43, 43, 82, 37, 57, 29, 286, 3, 29, 38, 
37, 115, 6, 40, 90, 121, 111, 170, 53, 48, 88, 126, 22, 78, 39, 
27, 23, 151, 26, 30, 55, 139, 53, 47, 48, 79, 11, 14, 0, 98, 
294, 88, 150, 114, 235, 44, 138, 363, 388, 175, 14, 50, 255, 
470, 141, 204, 43, 53, 139, 169, 186, 171, 75, 142, 150, 26, 
65, 13, 36, 85, 89, 144, 24, 108, 245, 100, 83, 211, 199, 78, 
87, 144, 4, 166, 363, 7, 141, 54, 55, 181, 89, 49, 100, 29, 72, 
9, 79, 63, 39, 215, 86, 150, 136, 435, 57, 333, 0, 59, 158, 110, 
403, 241, 0, 80, 83, 22, 207, 0, 45, 26, 21, 40, 0, 184, 62, 
133, 161, 0, 45, 0, 21, 12, 79, 12, 35, 14, 36, 4, 47, 23, 144, 
16, 33, 52, 15, 67, 10, 25, 1, 33, 6, 16, 9, 2, 15, 17, 33, 26, 
0, 37, 1, 4, 24, 17, 39, 92, 53, 9, 72, 27, 63, 41, 68, 9, 4, 
27, 47, 56, 2, 17, 22, 11, 1, 18, 68, 13, 10, 6, 12, 20, 65, 
12, 14, 26, 27, 155, 49, 25, 27, 40, 0)), row.names = c(NA, -328L
), spec = structure(list(cols = list(Ctyname = structure(list(), class = c("collector_character", 
"collector")), Stname = structure(list(), class = c("collector_character", 
"collector")), Cases2019 = structure(list(), class = c("collector_double", 
"collector"))), default = structure(list(), class = c("collector_guess", 
"collector")), delim = ","), class = "col_spec"), problems = <pointer: 0x60000397c050>, class = c("spec_tbl_df", 
"tbl_df", "tbl", "data.frame"))

Here is my code (note: for the color pallette, I was experimenting with some NY MET museum colors, this color palette is not necessary)

devtools::install_github("BlakeRMills/MetBrewer")
    library(MetBrewer)
LD <- LD_Case_Counts_by_County_00_19 %>% filter(Stname == "New York"|Stname=="Vermont"|Stname=="Vermont"|
                                                  Stname=="Wisconsin"|Stname=="New Hampshire"|Stname=="Connecticut"| Stname=="New Jersey"|
                                                  Stname=="Pennsylvania"|Stname=="Maine"|Stname=="Massachusetts"|Stname=="Rhode Island"|Stname=="Maryland"| Stname=="Delaware")

"State Name" <- LD$Stname                                          
                                          
ggplot(LD, aes(x=Cases2019, fill=`State Name`))  
  geom_histogram(bins=30,position="identity")  
  scale_fill_manual(values=met.brewer("Tam", 12))  theme_bw()   xlab("Lyme Disease Case Counts (2019)")   ylab("Frequency of Reported Cases")

Color package can be found here for anyone curious: enter image description here

  • Related