act5_tonyzhang

pdf

School

Pennsylvania State University *

*We aren’t endorsed by this school

Course

184

Subject

Computer Science

Date

Apr 3, 2024

Type

pdf

Pages

13

Uploaded by MajorMaskMule13

Report
Graph Exploration Tony Zhang 2/20/2024 Use Headers Use headers to organize your document. The first level heading is denoted by a single pound sign/hash tag, # . Each new problem/exercise should get a Level 1 Heading. For subparts, increase the heading level by increasing the number of hash tags. For example, if Problem 1 has Parts A (with parts i-ii) and B, your R Markdown file would have the following: # Problem 1 [text] ## Part A [text] ### Part i [text] ### Part ii [text] ## Part B [text] Code There are two ways to include code in your document: inline and chunks. Inline Code To add inline code, you’ll need to type a grave mark ‘ (the key to the left of the numeral 1 key), followed by a lower case r, a space, then the R commands you wish to r and a final grave. For example ‘ r nrow(dataFrame) ‘ would return the number of rows in the data frame named “dataFrame”. Inline code is good for calling values you have stored and doing quick calculations on those values. Inline code will not be added to the Code Appendix. Code Chunks For more complicated code such as data manipulation and cleaning, creating graphs or tables, model building and testing, you’ll want to use code chunks. You can do this in two ways: You can click the Insert button found just above the RStudio’s editor page (has an icon of a white circle with a green plus sign and a green square with a white C) and selecting R from the drop down list. You can create your own code chunk by typing three graves in a row, returning twice and typing three more graves. You should see the editor become shaded gray for those three lines. You will want to write your code starting in the middle blank line. In the first line, right after the third grave, you’ll want to set options including coding language and chunk name as well as other options (e.g., figure caption and dimensions). 1
Mathematics To type mathematical formulas, you will need to use LaTeX commands. For inline mathematics you’ll need to enclose your mathematical expression in \( and \). For display math (on it’s own line and centered), enclose the expression in \[ and \]. The following code will automatically create your Code Appendix by grabbing all of your code chunks and writing that code here. Take a moment to look through the appendix and make sure that your code is fully readable. Use comments in your code to help create markers for what code does what. 2
Code Appendix # This template file is based off of a template created by Alex Hayes # https://github.com/alexpghayes/rmarkdown_homework_template # Setting Document Options knitr :: opts_chunk $ set ( echo = TRUE , warning = FALSE , message = FALSE , fig.align = "center" ) install.packages ( "tidyverse" , repos = "http://cran.us.r-project.org" ) library (tidyverse) set.seed ( 1 ) SmDia <- diamonds %>% sample_n ( size = 2000 ) ggplot (SmDia) + aes ( x = carat, y = price) + geom_point ( shape = "circle" , size = 1.5 , colour = "#112446" ) + theme_minimal () ggplot (SmDia) + aes ( x = carat, y = price, colour = clarity) + geom_point ( shape = "circle" , size = 1.5 ) + scale_color_hue ( direction = 1 ) + theme_minimal () ggplot (SmDia) + aes ( x = clarity, fill = clarity) + geom_bar () + scale_fill_hue ( direction = 1 ) + theme_minimal () ggplot (SmDia) + aes ( x = cut, fill = cut) + geom_bar () + scale_fill_hue ( direction = 1 ) + theme_minimal () average_price <- SmDia %>% group_by (cut) %>% summarise ( "Average Price" = mean (price)) ggplot (average_price) + aes ( x = cut, y = ` Average Price ` , fill = cut) + geom_col () + scale_fill_hue ( direction = 1 ) + theme_minimal () ggplot (SmDia) + aes ( x = clarity, fill = cut) + geom_bar () + scale_fill_hue ( direction = 1 ) + theme_minimal () ggplot (SmDia) + aes ( x = clarity, fill = cut, group = cut) + geom_bar ( position = "dodge" ) + scale_fill_hue ( direction = 1 ) + theme_minimal () ggplot (SmDia) + 3
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
aes ( x = carat) + geom_histogram ( bins = 30L, fill = "#112446" ) + theme_minimal () ggplot (SmDia) + aes ( x = depth) + geom_histogram ( bins = 30L, fill = "#112446" ) + theme_minimal () Problem 1 install.packages ( "tidyverse" , repos = "http://cran.us.r-project.org" ) ## package ’tidyverse’ successfully unpacked and MD5 sums checked ## ## The downloaded binary packages are in ## C:\Users\tonyz\AppData\Local\Temp\RtmpspDhSQ\downloaded_packages library (tidyverse) set.seed ( 1 ) SmDia <- diamonds %>% sample_n ( size = 2000 ) Part a Part a-1 ggplot (SmDia) + aes ( x = carat, y = price) + geom_point ( shape = "circle" , size = 1.5 , colour = "#112446" ) + theme_minimal () 4
0 5000 10000 15000 0 1 2 3 4 5 carat price Part a-2 ggplot (SmDia) + aes ( x = carat, y = price, colour = clarity) + geom_point ( shape = "circle" , size = 1.5 ) + scale_color_hue ( direction = 1 ) + theme_minimal () 5
0 5000 10000 15000 0 1 2 3 4 5 carat price clarity I1 SI2 SI1 VS2 VS1 VVS2 VVS1 IF Part b Part b-1 ggplot (SmDia) + aes ( x = clarity, fill = clarity) + geom_bar () + scale_fill_hue ( direction = 1 ) + theme_minimal () 6
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
0 100 200 300 400 500 I1 SI2 SI1 VS2 VS1 VVS2 VVS1 IF clarity count clarity I1 SI2 SI1 VS2 VS1 VVS2 VVS1 IF ggplot (SmDia) + aes ( x = cut, fill = cut) + geom_bar () + scale_fill_hue ( direction = 1 ) + theme_minimal () 7
0 200 400 600 Fair Good Very Good Premium Ideal cut count cut Fair Good Very Good Premium Ideal Part b-2 average_price <- SmDia %>% group_by (cut) %>% summarise ( "Average Price" = mean (price)) ggplot (average_price) + aes ( x = cut, y = ` Average Price ` , fill = cut) + geom_col () + scale_fill_hue ( direction = 1 ) + theme_minimal () 8
0 1000 2000 3000 4000 5000 Fair Good Very Good Premium Ideal cut Average Price cut Fair Good Very Good Premium Ideal Part b-3 ggplot (SmDia) + aes ( x = clarity, fill = cut) + geom_bar () + scale_fill_hue ( direction = 1 ) + theme_minimal () 9
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
0 100 200 300 400 500 I1 SI2 SI1 VS2 VS1 VVS2 VVS1 IF clarity count cut Fair Good Very Good Premium Ideal Part b-4 ggplot (SmDia) + aes ( x = clarity, fill = cut, group = cut) + geom_bar ( position = "dodge" ) + scale_fill_hue ( direction = 1 ) + theme_minimal () 10
0 50 100 150 I1 SI2 SI1 VS2 VS1 VVS2 VVS1 IF clarity count cut Fair Good Very Good Premium Ideal Part b-5 ggplot (SmDia) + aes ( x = carat) + geom_histogram ( bins = 30L, fill = "#112446" ) + theme_minimal () 11
0 200 400 0 1 2 3 4 5 carat count ggplot (SmDia) + aes ( x = depth) + geom_histogram ( bins = 30L, fill = "#112446" ) + theme_minimal () 12
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
0 100 200 300 55 60 65 70 depth count 13