0

I am trying to create a box plot that shows the variance for values from 8 cities. With them being displayed using facets based on education attainment levels. Here is data frame 1 data frame

for example I want to see how much variance there is between HS_grad numbers for all the cities. facets groupings

Update

Here is data frame 2 data frame2

sudo97
  • 904
  • 2
  • 11
  • 22

1 Answers1

0

Welcome! Please read up on How to make a great R reproducible example.

Based on your screenshots, you will need to convert your dataset into a "long format" rather than the current "wide format". I think the code below should achieve what you want.

# Install packages
install.packages("tidyverse")

# Load
library(tidyverse)

# "df" is your data frame as shown in your screenshot
df %>%
  # Change from wide to long format
  gather(City, Value, -EA) %>%
  # Plot
  ggplot(aes(x = EA, y = Value)) +
  facet_wrap(~ City) +
  geom_boxplot()
conor
  • 1,204
  • 1
  • 18
  • 22
  • Thank you! this is headed in the right direction,but..... How do I create a new column that assigns the education category to a value, Chicago 22.9 HS_Grad – dasuperfan Feb 19 '20 at 01:49
  • Perhaps I misunderstood. Are you saying you want a boxplot for each EA which uses the numbers from all cities? In that case just comment out the `facet_wrap` line above. Or if you want each EA in its own facet, change the ggplot line to `x = 0` and `facet_wrap(~ EA)` – conor Feb 19 '20 at 06:18
  • Providing your data or a reproducible example would help. – conor Feb 19 '20 at 06:19