Module # 9 Visualization in R

 In this module, we reviewed three types of visualization in R: basic visualization without any package, lettuce and ggplot2.

Choose any data set for your visualization from Vincent Arel Bundock dataset list: https://vincentarelbundock.github.io/Rdatasets/datasets.htmlLinks to an external sit Using this data, generate three types of visualization on the data set you have chosen. In your blog, discuss and present your three visualizations you will create and express your opinion on these three different types of graphics output.



The dataset that I will be using is titled "Tips". This is an example dataset with values such as total_bill, tip, sex, smoker, day, time, and size. Below is a screenshot of the data. 




Bar Chart
The first graph I will be making is a simple bar chart that shows the total value of tips per day. This way we can see what day provides the most tips. From this chart, we are easily able to see that Saturday is the day with the most tips. Surprisingly, Friday had the least amount of tips while Thursday had more. I believe this is a good visualization because it is simple, effective, and visually appealing with the use of colors. 



> #bar chart
> ggplot(df, aes(x = day, y = tip, fill = day)) +
+   geom_bar(stat = "summary", fun = sum) +
+   labs(title = "Total value of Tips per Day", x = "Day of the Week", y = "Tips collected at E.O.D($)")




Boxplot
The next visualization that I wanted to do was create a boxplot that showed the difference of distribution between male and female based off tips. Based on the visualization seen below, we can see that men and women tipped roughly the same amount. The only difference is that under "men" there were a few more outliers. I think the best part of this visualization is the use of color to differentiate the sexes.  



> #box plot
> ggplot(df, aes(x = sex, y = tip, fill = sex)) +
+   geom_boxplot() +
+   scale_fill_manual(values = c("pink", "lightblue")) +
+   labs(title = "Distribution of Tips by Gender", x = "Gender", y = "Tips($)") 



Scatterplot
The next visualization will be a little more complex. I wanted to create a scatterplot that shows the relationship between the total bill vs. the tip amount depending on the time of day. Does a higher total bill mean higher tips? From this visualization we can see that is not always true. Some people tip low on high bills while others tip high on lower bills. Another thing we can see from this scatterplot is that people who eat during lunch tend to have smaller bills as well as smaller tips. People who eat during dinner have a higher dispersion. There are a lot more higher outliers with dinner. I believe this visualization is interesting because it disproved and also further supported some hypothesis I made. This is a simple chart that is easy to follow, even with more variables involved. 




> #scatter plot
> ggplot(df, aes(x = total_bill, y = tip, color = time)) +
+   geom_point(alpha = 0.6, size = 3) +
+   labs(title = "Scatter Plot of Tips vs.Total Bill depending on Time of Day",
+        x = "Total Bill ($)", y = "Tips ($)", color = "Time of Day")











My github

or 

https://github.com/AlenjaksAbraham/LIS4370.git


To see the code look under Module 9.R. 





Comments

Popular posts from this blog

Module # 7 R Object: S3 vs. S4 assignment

Module # 10 Building your own R package