Creating a One-Dimensional Bar Chart

Use the ggplot(df_vanc,aes(x=Vancouver)) + geom_bar() command to obtain the following chart:

Observations

Vancouver has clear weather, for the most part. It rained about 10,000 times for the dataset provided. Snowy periods are much less frequent.

We will now perform two exercises, creating a one-dimensional bar chart and a two-dimensional bar chart. A one-dimensional bar chart can give us the counts or frequency of a given variable. A two-dimensional bar chart can give us the
relationship between the variables.

In this section, we'll count the number of times each type of weather occurs in Seattle and compare it to Vancouver.

Let's begin by following these steps:

  1. Use ggplot2 and geom_bar in conjunction to create the bar chart.
  2. Use the data frame that we just created, but with Seattle instead of Vancouver, as follows:
ggplot(df_vanc,aes(x=Seattle)) + geom_bar() 
  1. Now, compare the two bar charts and answer the following questions:
  • Approximately how many times was Vancouver cloudy? (Round to 2 significant figures.)
  • Which of the two cities sees a greater amount of rain?
  • What is the percentage of rainy days versus clear days? (Add the two counts and give the percentage of days it rains.)
  • According to this dataset, which city gets a greater amount of snow?

You should see the following output:


Refer to the complete code at https://goo.gl/tu7t4y.

Answers

  • Vancouver was cloudy 13,000 times. (Note that 12,000 is also acceptable.)
  • Seattle sees a greater amount of rain.
It rained on approximately 40% of the days.
  • Vancouver gets a greater amount of snow.

A two-dimensional bar chart can be used to plot the sum of a continuous variable versus a categorical or discrete variable. For example, you might want to plot the total amount of rainfall in different weather conditions, or the total amount of sales in different months.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.134.78.106