Week 4 – More about visualizations, aesthetics, and annotations

1. Which of the following are benefits of using ggplot2? Select all that apply.

Answers

·        Customize the look and feel of your plot

·        Easily add layers to your plot

·        Combine data manipulation and visualization

·        Automatically clean data before creating a plot

2. A data analyst creates a bar chart with the diamonds dataset. They begin with the following line of code:

ggplot(data = diamonds)

What symbol should the analyst put at the end of the line of code to add a layer to the plot?

Answers

·        pipe operator (%>%)

·        plus sign (+)

·        equal sign (=)

·        ampersand symbol (&)

3. A data analyst creates a plot using the following code chunk:

ggplot(data = penguins) + geom_point(mapping = aes(x = flipper_length_mm, y = body_mass_g))

Which of the following represents a function in the code chunk? Select all that apply.

Answers

·        The aes function

·        The geom_point function

·        the data function

·        The ggplot function

4. Fill in the blank: In ggplot2, the term mapping refers to the connection between variables and _____ .

Answers

·        data frames

·        geoms

·        facets

·        aesthetics

ghyIn the context of ggplot2, the word "mapping" refers to the relationship that exists between aesthetics and variables.

5. A data analyst creates a scatterplot with a lot of data points. The analyst wants to make some points on the plot more transparent than others. What aesthetic should the analyst use?

Answers

·        Color

·        Shape

·        Alpha

·        Fill

Explanation: It is recommended that the analyst experiment with the "alpha" aesthetic in this particular scenario. Making adjustments to the alpha value gives them the ability to regulate the degree to which the points on the scatterplot are transparent. Therefore, a larger alpha resulted in more transparency, whereas a lower alpha resulted in less transparency. Adjusting the opacity slider for your data points is very much the same thing!

6. You are working with the penguins dataset. You create a scatterplot with the following code:

ggplot(data = penguins) +

geom_point(mapping = aes(x = flipper_length_mm, y = body_mass_g))

You want to highlight the different penguin species on your plot. Add a code chunk to the second line of code to map the aesthetic shape to the variable species.

NOTE: the three dots (...) indicate where to add the code chunk.

Which penguin species does your visualization display?

Answers

·        Adelie, Chinstrap, Gentoo

·        Emperor, Chinstrap, Gentoo

·        Adelie, Chinstrap, Emperor

·        Adelie, Gentoo, Macaroni

7. A data analyst creates a plot with the following code chunk:

ggplot(data = penguins) +

geom_jitter(mapping = aes(x = flipper_length_mm, y = body_mass_g))

What does the geom_jitter() function do to the points in the plot?

Answers

·        Adds a small amount of random shapes at each point in the plot

·        Decrease the size of each point in the plot

·        Adds a small amount of random noise to each point in the plot

·        Adds random colors to each point in the plot

8. You are working with the diamonds dataset. You create a bar chart with the following code:

ggplot(data = diamonds) +

geom_bar(mapping = aes(x = color, fill = cut)) +

You want to use the facet_wrap() function to display subsets of your data. Add the code chunk that lets you facet your plot based on the variable clarity.

How many subplots does your visualization show?

Answers

·        9

·        6

·        8

·        7

9. Fill in the blank: You can use the _____ function to put a text label on your plot to call out specific data points.

Answers

·        annotate()

·        ggplot()

·        facet_grid() 

·        geom_smooth()

Explanation: You are able to make use of the text function in order to add a text label to your plot in order to highlight certain data points. The addition of useful annotations to your visualizations is made much easier using this method!

10. You are working with the penguins dataset. You create a scatterplot with the following lines of code:

ggplot(data = penguins) +

geom_point(mapping = aes(x = flipper_length_mm, y = body_mass_g)) +

What code chunk do you add to the third line to save your plot as a png file with “penguins” as the file name?

Answers

·        ggsave(“penguins”)

·        ggsave(penguins.png)

·        ggsave(“png.penguins”)

·        ggsave(“penguins.png”)

Shuffle Q/A 1

11. In ggplot2, what symbol do you use to add layers to your plot?

Answers

·        The pipe operator (%>%)

·        The plus sign (+)

·        The ampersand symbol (&)

·        The equals sign (=)

Explanation: For the purpose of adding layers to your plot, the addition sign (+) is used in ggplot2. The process is analogous to constructing your story in stages, adding various elements and layers in order to get a representation that is both thorough and useful.

12. A data analyst creates a plot using the following code chunk:

ggplot(data = buildings) +

geom_bar(mapping = aes(x = construction_year, color = height))

Which of the following represents an aesthetic attribute in the code chunk?

Answers

·        ggplot

·        construction_year

·        buildings

·        x


13. Which code snippet will make all of the bars in the plot have different colors based on their heights?

Answers

·        ggplot(data = buildings) +

geom_bar(mapping = aes(x = construction_year), color=height)

·        ggplot(data = buildings) +

geom_bar(mapping = aes(x = construction_year)) +

color(“height”)

·        ggplot(data = buildings) +

geom_bar(mapping = aes(x = construction_year, color=height))

·        ggplot(data = buildings) +

geom_bar(mapping = aes(x = construction_year)) +

color(height)


14. What is the purpose of the facet_wrap() function?

Answers

·        Modify the visual characteristic of a data point

·        Modify ggplot visuals to be three-dimensional

·        Create text inside a plot area

·        Create subplots in a grid of two variables

Explanation: It is possible to generate a multi-panel plot in ggplot2 by "wrapping" a category variable using the facet_wrap() function by using the function. It is especially helpful in situations in which you want to compare the same sort of graphic for several levels or categories of a variable.

For instance, if you have a category variable that has many levels and you want to generate different plots for each level, you may use the facet_wrap() function. Specifically, it generates a grid of panels, each of which represents a distinct level of the category variable, and it shows the same style of plot in each of the panels.

 

15. A data analyst uses the annotate() function to create a text label for a plot. Which attributes of the text can the analyst change by adding code to the argument of the annotate() function? Select all that apply.

Answers

·        Change the font style of the text.

·        Change the color of the text.

·        Change the size of the text.

·        Change the text into a title for the plot.


16. Which statement about the ggsave() function is correct?

Answers

·        ggsave() exports the last plot displayed by default.

·        ggsave() is run from the Plots Tab in RStudio.

·        ggsave() is the only way to export a plot.

·        ggsave() is unable to save .png files.


17. Which of the following statements about ggplot is true?

Answers

·        ggplot allows analysts to create plots using a single function.

·        ggplot is the default plotting package in base R.

·        ggplot allows analysts to create different types of plots.

·        ggplot is designed to make cleaning data easy.

Explanation: For the purpose of this updated example, the file type is defined as "png," and the dimensions are set to 8 inches by 6 inches, with the units parameter being set to "in" for inches. Your tastes and needs may be taken into consideration when making adjustments to these settings.

 

18. A data analyst creates a plot using the following code chunk:

ggplot(data = buildings) +

geom_bar(mapping = aes(x = construction_year, color = height))

Which of the following represents a variable in the code chunk?

Answers

·        construction_year

·        mapping

·        data

·        ggplot


19. Which ode snippet will make all of the bars in the plot purple?

Answers

·        ggplot(data = buildings) +

geom_bar(mapping = aes(x = construction_year, color=”purple”))

·        ggplot(data = buildings) +

geom_bar(mapping = aes(x = construction_year)) +

color(“purple”)

·        ggplot(data = buildings) +

geom_bar(mapping = aes(x = construction_year, color=height))

·       ·       ggplot(data = buildings) +

geom_bar(mapping = aes(x = construction_year), color=”purple”)


20. A data analyst is working with the following plot and gets an error caused by a bug. What is the cause of the bug?

ggplot(data = penguins) %>%

geom_point(mapping = aes(x = flipper_length_mm, y = body_mass_g))

Answers

·        The code uses a pipe instead of a plus sign.

·        A missing closing parenthesis needs to be added.

·        The pipe should be at the beginning of the second line.

·        A function name needs to be capitalized.


21. You are working with the penguins dataset. You create a scatterplot with the following code chunk:

ggplot(data = penguins) +

geom_point(mapping = aes(x = flipper_length_mm, y = body_mass_g))

You want to highlight the different penguin species in your plot. Add a code chunk to the second line of code to map the aesthetic size to the variable bill_depth_mm.

NOTE: the three dots (...) indicate where to add the code chunk. You may need to scroll in order to find the dots.

Which approximate range of bill depths does your visualization display?

Answers

·        2 – 9

·        31 – 40

·        20 – 31

·        14 – 20


22. A data analyst has a scatter plot with crowded points that make it hard to identify a trend. What geometry function can they add to their plot to clearly indicate the trend of the data?

Answers

·        geom_alpha()

·        geom_bar()

·        geom_jitter()

·        geom_smooth()

Explanation: Adding a smoother line to a scatter plot that has congested spots is something that a data analyst may do using the geom_smooth() geometry function. This will allow the data analyst to clearly highlight the trend of the data. This function provides a visual representation of the trend in the data by fitting a regression line or a loess curve to the scatter plot (also known as a distribution curve).

Shuffle Q/A 2

23. A data analyst wants to add a large piece of text above the grid area that clearly defines the purpose of a plot. Which ggplot function can they use to achieve this?

Answers

·        subtitle()

·        title()

·        labs()

·        annotate()


24. By default, what plot does the ggsave() function export?

Answers

·        The plot define the plots.config file

·        The last displayed plot

·        The plot defined in the Plots Tab of R Studio

·        The first plot displayed

Explanation: The ggsave() method in ggplot2 exports the most recent plot that was made or printed during the R session. This is the default behavior. It will store the most recent ggplot object that was created by the ggplot() method, as well as any adjustments that were made to that plot after it was constructed.

25. Which of the following tasks can you complete with ggplot2 features? Select all that apply.

Answers

·        Customize the visual features of a plot

·        Automatically clean data before creating a plot

·        Add labels and annotations to a plot

·        Create many different types of plots


26. A data analyst is working with the following plot and gets an error caused by a bug. What is the cause of the bug?

ggplot(data = penguins)

+ geom_point(mapping = aes(x = flipper_length_mm, y = body_mass_g))

Answers

·        The plus should be at the end of the first line.

·        A missing closing parenthesis needs to be added.

·        The code uses a plus sign instead of a pipe.

·        A function name needs to be capitalized.


27. You are working with the penguins dataset. You create a scatterplot with the following code chunk:

ggplot(data = penguins) +

geom_point(mapping = aes(x = flipper_length_mm, y = body_mass_g))

You want to highlight the different penguin species in your plot. Add a code chunk to the second line of code to map the aesthetic shape to the variable species.

NOTE: the three dots (...) indicate where to add the code chunk. You may need to scroll in order to find the dots.

Which species tends to have the longest flipper length and highest body mass?

Answers

·        Gentoo

·        Macaroni

·        Adelie

·        Chinstrap


28. A data analyst creates a scatterplot where the points are very crowded, which makes it hard to notice when points are stacked. What change can they make to their scatter plot to make it easier to notice the stacked data points?

Answers

·        Change geom_point() to geom_jitter()

·        Change ggplot() to ggplot2()

·        Change the color of the points

·        Change the shape of the points


29. Which code snippet will make all of the bars in the plot have different colors and shapes based on their heights?

Answers

·        ggplot(data = buildings) +

geom_bar(mapping = aes(x = construction_year, color=[height, height]))

       ·       ggplot(data = buildings) +

geom_bar(mapping = aes(x = construction_year, color=height, shape=height))

·        ggplot(data = buildings) +

geom_bar(mapping = aes(x = construction_year, color=height), aes(shape=height))

       ·       ggplot(data = buildings) +

geom_bar(mapping = aes(x = construction_year)) +

color(height) +

shape(height)

30. You are working with the penguins dataset. You create a scatterplot with the following code:

ggplot(data = penguins) +

geom_point(mapping = aes(x = flipper_length_mm, y = body_mass_g))

You want to highlight the different years of data collection on your plot. Add a code chunk to the second line of code to map the aesthetic size to the variable year.

NOTE: the three dots (...) indicate where to add the code chunk. You may need to scroll in order to find the dots.

What years does your visualization display?

Answers

·        2006-2010

·        2005-2009

·        2007-2009

·        2007-2011 

31. Fill in the blank: The _____ creates a scatterplot and then adds a small amount of random noise to each point in the plot to make the points easier to find.

Answers

·        geom_jitter() function

·        geom_point() function

·        geom_bar() function

·        geom_smooth() function

Explanation: In order to make the points in the scatterplot more easily identifiable, the geom_jitter() function first generates a scatterplot and then adds a little amount of random noise to each point in the plot. A good method for preventing overplotting in situations when there is a large density of dots is to employ this strategy.

 

32. A data analyst creates a plot using the following code chunk:

ggplot(data = buildings) +

geom_bar(mapping = aes(x = construction_year, color = height))

Which of the following represents a function in the code chunk?

Answers

·        The height function

·        The x function

·        The ggplot function

·        The mapping function


33. A data analyst is working with the following plot and gets an error caused by a bug. What is the cause of the bug?

ggplot(data = penguins) +

geom_point(mapping = aes(x = flipper_length_mm, y = body_mass_g)

Answers

·        A missing closing parenthesis needs to be added.

·        The plus sign should be at the beginning of the second line.

·        The code uses a plus sign instead of a pipe.

·        A function name needs to be capitalized.


34. Which of the following statements best describes a facet in ggplot?

Answers

·        Facets are the ggplot terminology for a chart axis.

·        Facets are subplots that display data for each value of a variable.

·        Facets are the visual characteristics of geometry objects.

·        Facets are the text used in and around plots.

Explanation: When using ggplot, the term "facet" refers to the process of generating a number of smaller subplots that are dependent on the levels of a categorical variable. Because of this, you are able to see the same sort of plot for many groups or categories, which makes it much simpler to examine patterns and trends across those groupings. Faceting is a strong function in ggplot2 that improves the clarity of complicated datasets and makes them easier to grasp.

Shuffle Q/A 3


35. Which of the following is a functionality of ggplot2?

Answers

·        Combine data manipulation and visualizations using pipes.

·        Filter and sort data in complex ways.

·        Define complex visualization using a single function.

·        Create plots using artificial intelligence.

Explanation: Ggplot2 is capable of producing intricate visuals from data, which is one of its capabilities. For the purpose of producing a broad range of static visuals, such as scatter plots, line charts, bar graphs, histograms, and many more, it offers a high-level interface. The design of your plots may be customized with ggplot2, you can include labels and annotations, you can facet the data, and you can easily manage a variety of data types. When it comes to data visualization in R, it is a tool that is both diverse and strong.

 

36. Which ggplot function is used to define the mappings of variables to visual representations of data?

Answers

·        annotate()

·        mapping()

·        aes()

·        ggplot()

Explanation: It is possible to specify the mappings of variables to visual representations of data by using the aes() function, which is an abbreviation for the aesthetics function found in ggplot2. For the purpose of specifying how variables should be represented in terms of aesthetics, such as x and y locations, colors, forms, sizes, and so on, it is often used inside the ggplot() function.

37. You are working with the penguins dataset. You create a scatterplot with the following code chunk:

ggplot(data = penguins) +

geom_point(mapping = aes(x = flipper_length_mm, y = body_mass_g))

You want to highlight the different years of data collection on your plot. Add a code chunk to the second line of code to map the aesthetic alpha to the variable island.

NOTE: the three dots (...) indicate where to add the code chunk. You may need to scroll in order to find the dots.

What islands does your visualization display?

Answers

·        Biscoe, Dream, Torgersen

·        Cebu, Borneo, Torgersen

·        Cebu, Java, Hispaniola

·        Biscoe, Java, Buton

38. What function creates a scatterplot and then adds a small amount of random noise to each point in the plot to make the points easier to find?

Answers

·        The geom_smooth() function

·        The geom_jitter() function

·        The geom_point() function

·        The geom_bar() function

Explanation: The geom_jitter() function in ggplot2 is responsible for the creation of a scatterplot, which is followed by the addition of a nominal amount of random noise to every point in the plot. When there is a high density of data, this is done to avoid overplotting and to make it simpler to differentiate between individual point.

39. A data analyst wants to add text elements inside the grid area of their plot. Which ggplot function allows them to do this?

Answers

·        annotate()

·        labs()

·        facet()

·        text()

40. You are working with the penguins dataset. You create a scatterplot with the following lines of code:

ggplot(data = penguins) +

geom_point(mapping = aes(x = flipper_length_mm, y = body_mass_g)) +

What code chunk do you add to the third line to save your plot as a pdf file with “penguins” as the file name?

Answers

·        ggsave(penguins.pdf)

·        ggsave(“pdf.penguins”)

·        ggsave(=penguins)

·        ggsave(“penguins.pdf”)

41. A data analyst creates a plot using the following code chunk:

ggplot(data = penguins) +

geom_point(mapping = aes(x = flipper_length_mm, y = body_mass_g))

Which of the following represents an aesthetic attribute in the code chunk? Select all that apply.

Answers

·        flipper_length_mm

·        body_mass_g

·        y

·        x

42. What argument of the labs() function can a data analyst use to add text outside of the grid area of a plot?

Answers

·        text

·        note

·        title

·        annotate

Explanation: The title argument of the labs() method in ggplot2 is what a data analyst may use to add text to a plot that is located outside of the grid area included inside the plot. To be more specific, title is used to add a title to the whole plot, and this title is often positioned outside of the grid area.

43. In R studio, what default options does the Export functionality of the Plots tab give for exporting plots?

Answers

·        HTML

·        Image

·        Slideshow

·        PDF

44. Fill in the blank: In ggplot2, you use the _____ to add layers to your plot.

Answers

·        The plus sign (+)

·        The pipe operator (%>%)

·        The equals sign (=)

·        The ampersand symbol (&)

Explanation: For the purpose of adding layers to your plot with ggplot2, you may use the addition sign (+). This gives you the ability to gradually construct your visualization by adding various components and layers in order to get a plot that is both complete and interesting.

45. A data analyst is working with the penguins data. The analyst creates a scatterplot with the following code:

ggplot(data = penguins) +

geom_point(mapping = aes(x = flipper_length_mm, y = body_mass_g, alpha = species))

What does the alpha aesthetic do to the appearance of the points on the plot?

Answers

·        Makes the points on the plot larger

·        Makes some points on the plot more transparent

·        Makes the points on the plot smaller

·        Makes the points on the plot more colorful

46. You are working with the diamonds dataset. You create a bar chart with the following code:

ggplot(data = diamonds) +

geom_bar(mapping = aes(x = color, fill = cut)) +

You want to use the facet_wrap() function to display subsets of your data. Add the code chunk that lets you facet your plot based on the variable cut.

How many subplots does your visualization show?

Answers

·        3

·        4

·        5

·        6

Post a Comment

Previous Post Next Post