Module 9 Assignment

 Module 9 Assignment


Dataset: Pulse Rates at Various Times of Day - A student measured her pulse in the morning, at noon, at 1:00, and in the evening for each of 26 days.

pulse_data has 104 total observations for 26 days and 4 conditions (morning, noon, one, evening). 

#1

First visualization: heart rate in the morning
    I wanted to make a simple visualization of a scatterplot using base R that displays all the morning heart rate recordings for all 26 days. I first created a subset data frame using the dplyr package that contains the values from pulse_data that contain "morning" in the time column. I then plotted these readings to show the heart rate in the morning graph, with day as the x value and heart rate as the y value. As seen in the graph, the heart rate readings were clustered between 65-75 bpm. 

#2

Second visualization: heart rate in the morning compared to heart rate in the evening
    For my second visualization, I wanted to make a graph that is able to show comparison between all of the heart rates at different times of the day, so all of the morning and all of the evening readings for all 26 days. I again used the dplyr package to make a pulse_night data frame that only included the evening readings for heart rate. I then figured out I could not use the "Days" column as the x variable because it made the x bar look horrendous since all the values were recorded as "Day#". I decided to use the rownames column instead because they were just numbers, but I had to change the rownames values in pulse_night because they did not start at 1 like in pulse_morning. Once that was figured out, I was able to plot both data frames using ggplot2. I assigned the different data sets different colors, blue for morning and red for evening, and made a legend to distinguish them. The graph shows that the person's heart rate skewed higher in the evening compared to the morning. 

#3

    Third visualization: heart rate throughout the day for days 1-3 and 26
    For my third graph I wanted to compare how the heart rate for the person changed throughout the day on different days using a line graph. I chose the first three days of recordings and the last day of recordings. I first created the subset data frames day1, day2, day3, and day26 similar to how I created the first two. I once again changed the rownames values to 1-4 to use as my x variable. I used ggplot2 geom_point() to plot the data points and geom_line() to create the lines connecting the data points. I gave the different days different color points and lines. I manually changed the x bar variables from the rownames values to "morning", "noon", "1 PM", and "evening" to give the graph clear meaning. I added the legend to show which colors correspond to which day. I played around with themes and chose theme_classic() for a clean look. Lastly, I adjusted the title to be centered instead of left-skewed. The graph shows that the person's heart rate increased throughout the day for days 1-3, but decreased on day 26. 

    Overall, I learned that base R is a very easy way to create simple graphs. However, for more nuanced graphs, ggplot2 was easy and straightforward to use. 


Weekly Readings

Comments

Popular posts from this blog

Module 10 Assignment

Module 1 Assignment