Question

On R: Run ggplot(data = mpg). What do you see? How many rows are in mpg?...

  1. On R:
  1. Run ggplot(data = mpg). What do you see?
  2. How many rows are in mpg? How many columns?
  3. What does the drv variable describe? Read the help for ?mpg to find out.
  4. Make a scatterplot of hwy vs cyl.
  5. What happens if you make a scatterplot of class vs drv? Why is the plot not useful?
  6. What’s gone wrong with this code? Why are the points not blue?
  7. ggplot(data = mpg) +
  8. geom_point(mapping = aes(x = displ, y = hwy, color = "blue"))
  9. Which variables in mpg are categorical? Which variables are continuous? (Hint: type ?mpg to read the documentation for the dataset). How can you see this information when you run mpg?
  10. Map a continuous variable to color, size, and shape. How do these aesthetics behave differently for categorical vs. continuous variables?
  11. What happens if you map the same variable to multiple aesthetics?
  12. What does the stroke aesthetic do? What shapes does it work with? (Hint: use ?geom_point)
  13. What happens if you map an aesthetic to something other than a variable name, like aes(colour = displ < 5)?
0 0
Add a comment Improve this question Transcribed image text
Answer #1

A-  ggplot(data = mpg) function creates the background of the plot, but no layer is specified with geom function, nothing is drawn.

B- To get the dimensions of a data matrix, we can simply use the function ‘dim()’. The rows and columns in mpg is [1] 234 11 .

C- The drv variable is a categorical variable which is used to categorize cars into front wheels , rear wheels or four wheel drive.

            f = front-wheel drive, r = rear wheel drive, 4 = four wheel drive

D - ggplot(mpg, aes(x = hwy, y = cyl)) + geom_point() this function creates the scatterplot of hwy and cyl

E- when we make a scatterplot of class vs drv the resulting scatterplot will have only few points.

Since div and class variables are categorical variable and categorical variables typically take a small number of values so there are a limited number of unique combinations of (x, y) values that can be displayed. Therefore scatter plot is not used to display these variables.

F- The argument colour = "blue" is included within the mapping argument, and as such, it is treated as an aesthetic, which is a mapping between a variable and a value. In the expression, colour = "blue", "blue" is interpreted as a categorical variable which only takes a single value "blue". If this is confusing, consider how colour = 1:234 and colour = 1 are interpreted by aes().

G- categorical variables in mpg

  • model
  • trans
  • drv
  • fl
  • class

continuous variables in mpg

  • displ
  • year
  • cyl
  • cty
  • hwy

glimpse() function displays the type of each column.

J- When a continuous value is mapped to shape, it gives an error. Though we could split a continuous variable into discrete categories and use a shape aesthetic, this would conceptually not make sense. A numeric variable has an order, but shapes do not. It is clear that smaller points correspond to smaller values, or once the color scale is given, which colors correspond to larger or smaller values. But it is not clear whether a square is greater or less than a circle.

K- Mapping a same variable to multiple aesthetics is redundant. Because it is redundant information, in most cases avoid mapping a single variable to multiple aesthetics.

L- Stroke changes the size of the border for shapes (21-25). These are filled shapes in which the color and size of the border can differ from that of the filled interior of the shape. For example,

ggplot(mtcars, aes(wt, mpg)) +
  geom_point(shape = 21, colour = "black", fill = "white", size = 5, stroke = 5)

M- Aesthetics can also be mapped to expressions like displ < 5. The ggplot() function behaves as if a temporary variable was added to the data with with values equal to the result of the expression. In this case, the result of displ < 5 is a logical variable which takes values of TRUE or FALSE.

Add a comment
Know the answer?
Add Answer to:
On R: Run ggplot(data = mpg). What do you see? How many rows are in mpg?...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I'm confused on how to approach this question, what statistical tests should I run to receive...

    I'm confused on how to approach this question, what statistical tests should I run to receive the required information? The data related to the health knowledge assessment scores in continuous and the variables it should be tested against are categorical. Test the association between the student’s health knowledge assessment score and the demographic variables (Gender, Race, and Family Income) and the behavior variables (Body Image, Sexual Activity, and Risk Behavior). Quantify the magnitude and significance of the association between the...

  • 1. For each of the following regression models, write down the X matrix and 3 vector....

    1. For each of the following regression models, write down the X matrix and 3 vector. Assume in both cases that there are four observations (a) Y BoB1X1 + B2X1X2 (b) log Y Bo B1XiB2X2+ 2. For each of the following regression models, write down the X matrix and vector. Assume in both cases that there are five observations. (a) YB1XB2X2+BXE (b) VYBoB, X,a +2 log10 X2+E regression model never reduces R2, why 3. If adding predictor variables to a...

  • What is the hypothesis and independent and dependent variable? 9. It turns out that the iridescent...

    What is the hypothesis and independent and dependent variable? 9. It turns out that the iridescent wing bands that shine blue-green when the pigeons flap around are actually dependent on heavy metals. You know that these iridescent wing bands are important in mate choice - females prefer mates with larger wing bands. For your summer project you decide to investigate the relationship between dark feathers, iridescent wing bands, and mating success in urban versus rural environments. You ask the research...

  • 1. How do you insert a “break point” in your script? 2. What happens to the...

    1. How do you insert a “break point” in your script? 2. What happens to the execution of a script when MATLAB encounters a break point? Is the execution ended? 3. What happens if a break point is inserted within a loop (like a for loop)? 4. How do you step through different lines of the code during the debugging session? 5. How can you see the values of a particular variable when the debug session is active? 6. Are...

  • 1. How many Timers does the F5529 have? Name them. What happens when the Timer overflows?...

    1. How many Timers does the F5529 have? Name them. What happens when the Timer overflows? And what exactly does "overflow" mean? 2. What is the name of the register that "counts?" 3. 4. What is the name of the Timer A Interrupt Flag? 5. What is "resolution?" State 2 ways you can change it. What are the different Timer Modes and how do they work? 6. 7. What is the advantage of Up Mode vs Continuous Mode? What settings...

  • 1.) How do you find what files are in a directory 2. How do you hide...

    1.) How do you find what files are in a directory 2. How do you hide a file 3. How do you find how much space is left on a disk 4. How do you find out how much space you are using 5. How do you find out how big a file is? 6. What does drwxr-xr-x mean? 7. What’s a group in unix? 8. What are the three sets of permisions in unix? 9. what does chmod 700...

  • 1.1 Fuel Economy. (mpg) of model year 2016 motor vehicles Here is a small part of a data set that...

    1.1 Fuel Economy. (mpg) of model year 2016 motor vehicles Here is a small part of a data set that describes the fuel economy in miles per gallon Make and Vehicle Class Transmission Number of City Highway Annual Fuel Model Type Cylinders mpg mpg Cost Subaru Im Compact preza Nissan Juke Small station Manual Manual 4 25 34 $900 4 28 34 1,100 wagon Midsize Hyundai Elantra GT Automatic 24 $950 19 Chevrolet Im Large pala Automatic 29 1,150 The...

  • Problem.2. Because of economic crisis Darth Vader ordered Data Analysis department of the Empire Inc. to...

    Problem.2. Because of economic crisis Darth Vader ordered Data Analysis department of the Empire Inc. to analyze the price factors of Star Fighters of different modifications. Data (N=74 obs) on the ion-fuel-economy (mpi), length, weight of carried laser arm (kg), Twin Ion Engine displacement (cubic cm) and Engine origin ( For Empire Inc., variable Foreign =0) were used to find out how the estimate of the price (SM) of Fighters depends on fuel economy. The results are following: reg price...

  • RESULTS: Analyzing your data Answer the following questions: 1) How many bands do you see in...

    RESULTS: Analyzing your data Answer the following questions: 1) How many bands do you see in the "unculanes? If there are more than one bad explain the nature or origin of the other bands? If there are more than one band can you 2) Why did you have to electrophorese uncut DNA? 3) What size of fragments were you expecting when you digested the known samples of pBR322 with the enzymes you used? 4) What are the sizes of the...

  • Need help with e-g please :) Business Calc... How Does Coffee Cool? How Long Do You Have Before You Can't Sue Anymor...

    Need help with e-g please :) Business Calc... How Does Coffee Cool? How Long Do You Have Before You Can't Sue Anymore? 4. The following data shows the temperature of a freshly brewed cup of coffee t minutes after it is removed from the pot. The temperature in the room is 80° F. Time (mins) Temp (F) temperature as the dependent variable. Displayed below c) Find a linear regression model for 179.6 168.8 158 149 141.8 134.6 125.6 123.8 116.6...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT