Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

### c . Create a table by merging the prior two tables, then melting to convert to long form. Don't change this code - just

### c. Create a table by merging the prior two tables, then melting to convert to long form.
Don't change this code - just run it.
```{r}
income_by_region_grouped_wide = merge(income_by_region %>% select(region, total_income),top_3_by_population,on="region")
income_by_region_grouped_long = melt(income_by_region_grouped_wide,variable.name = "income_category",value.name = "income",id.vars = "region")
income_by_region_grouped_long
```
### d*. Create a grouped bar plot from the income_by_region_grouped_long data to allow us to compare the total and top 3 states income in each region.
- Each region should have two bars in different colors - one color for total_income, and one color for top_3_income.
- Customize the plot by adding title/labels, adding a theme, and enlarging the font (see Q1; you can reuse the larger_font variable, if you wish).
After completing the steps above, improve the plot as follows:
- Instead of using *x=region*, use *x=fct_reorder2(region,income_category,income)*. Notice how the regions are now ordered by the length of one of the bars.
- Make the legend have a better title. You can do this inside the labs() command where you set the x label, y label, and title. Here you can use *fill="..."* to title the legend.
- Customize the colors by adding onto the plot a line of code like this (choose your own favorite color scheme!): *scale_fill_manual(labels=c("full region","most populated 3 states"),values=c("gray","slateblue"))*
```{r}
```
### e*. Create a stacked bar plot of income by region for the top 3 most populous states.
Hint: (code needed for full row for top 3 by population)%>% ggplot...
- Encode the states using the fill color.
- Add title, labels, a theme, and enlarged font.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Analysis Using SQL And Excel

Authors: Gordon S Linoff

2nd Edition

111902143X, 9781119021438

More Books

Students also viewed these Databases questions