logo Hurry, Grab up to 30% discount on the entire course
Order Now logo

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Seth PowelllEngineering
(5/5)

557 Answers

Hire Me
expert
Zuber KhanEconomics
(5/5)

932 Answers

Hire Me
expert
Witi HydeGeneral article writing
(5/5)

975 Answers

Hire Me
expert
joyComputer science
(4/5)

12 Answers

Hire Me
R Programming
(5/5)

There are different ways how to create such a new data frame; the easiest ways are probably using subset

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

Graphs and figures with ggplot2 

Visualize the dataset (i.e., dataframe) included with the ggplot2 package, called ‘mpg’. It describes the mileage (in miles per gallon) of cars from different manufacturers (manufacturer). 

The dataset describes different models (model), from different years (year), various numbers of cylinders (cyl), automatic or manual transmission (trans), 4-wheel, front or rear-wheel drive (drv), the cars’ class (class), and the cars’ mileage in a city (cty) and on the highway (hwy). 

For this homework, please copy/paste the figures that you create together with the respective R code and your interpretations into the word file. Please include APA style figure numbers, titles, notes.

Start with loading up the ggplot2 package and looking at a summary of the mpg dataframe. 

For points 1. to 4., use qplot(). From point 5. on, you better use ggplot().

2. Create a new data frame called mpgsmall containing a subset of the mpg data, with only the information about the following manufacturers: volkswagen, ford, honda, toyota. 

Hint: There are different ways how to create such a new data frame; the easiest ways are probably using subset() or using the %in% keyword. Do not forget to use droplevels().

Feel free to use the command that you prefer most; or try them all out to learn how they work.

3. Create a single graph that shows the distributions for city mileage for each of the manufacturer in mpgsmall with differently colored density plots. Then do the same, but with a histogram using faceting.
Discuss which plot is clearer and allows you to draw conclusions more easily. 

4. Create a scatter plot to show the relation between city and highway mileage in the mpgsmall dataset, using a different symbol for each class of car.
Discuss what you see. 

5. Come up with a better plot to examine whether the relationship in the previous graph is different for different classes, using different colored lines. Make sure the lines are easy to read. 

(Hints: (a) You could use qplot() for this plot but it will most likely not be as pretty as when you use ggplot()  and depending on what you do (for example specify method = "lm"), you might get a warning that some arguments are ignored or are not supported when you use qplot(); however, as we have seen in the class, the commands still seem to work, despite the warning.)

6. Create a bar chart showing the mean highway mileage for each class in mpgsmall using different colors for the various classes. 

7. Add error bars to the previous chart. 

8. Add a nice color theme from ggthemes and make the labels of the chart pretty for publication (make sure the theme can show the labels of the axes, thus do not use WSJ theme). 

9. Change the bar chart so that it shows a city mileage bar next to each highway mileage bar. 

Hint #1: For this, you will need to reshape the mpgsmall dataset so cty and hwy are stacked below each other in long format with a variable coding for whether the mileage is cty or hwy. 

Hint #2: The data mgp data set (and thus also mpgsmall data set that you created) has a special format, it is a so-called tibble (this is a new format developed by the guy who also developed the ggplot2 package). It has slightly different properties than a regular data frame and therefore the reshape command will most likely give you an error. The easiest workaround is to turn the data set into a regular data frame, with something like the following command:

mpgsmall_df <- as.data.frame(mpgsmall)

And then you use the data frame mpgsmall_df in the reshape command.

Hint #3: Before you can reshape the data frame, you will need to have a column coding for the idvar in the reshape command. You can do that with this line:
mpgsmall$id <- row.names(mpgsmall) 

Hint #4: Your long data set will have a new variable coding for whether the mileage is s cty or hwy. This new variable needs to be transformed into a factor in order for ggplot to be able to handle it as a discrete variable. Use the command as.factor() for that.

10. Go nuts in creating a really cool visualization from the mpg dataset using ggplot that differs a lot from the plots in the assignment so far. But be sure that the plot is still elegant and readable. Completely up to you, but a violin plot would be something good to practice. 

(5/5)
Attachments:

Related Questions

. The fundamental operations of create, read, update, and delete (CRUD) in either Python or Java

CS 340 Milestone One Guidelines and Rubric  Overview: For this assignment, you will implement the fundamental operations of create, read, update,

. Develop a program to emulate a purchase transaction at a retail store. This  program will have two classes, a LineItem class and a Transaction class

Retail Transaction Programming Project  Project Requirements:  Develop a program to emulate a purchase transaction at a retail store. This

. The following program contains five errors. Identify the errors and fix them

7COM1028   Secure Systems Programming   Referral Coursework: Secure

. Accepts the following from a user: Item Name Item Quantity Item Price Allows the user to create a file to store the sales receipt contents

Create a GUI program that:Accepts the following from a user:Item NameItem QuantityItem PriceAllows the user to create a file to store the sales receip

. The final project will encompass developing a web service using a software stack and implementing an industry-standard interface. Regardless of whether you choose to pursue application development goals as a pure developer or as a software engineer

CS 340 Final Project Guidelines and Rubric  Overview The final project will encompass developing a web service using a software stack and impleme