Posts

Showing posts from February, 2023

wk 8

Image
2023-02-28 # load the ggplot2 library library (ggplot2) library (reshape2) # calculate the correlation matrix correlation_matrix = cor (mtcars) # create a heatmap of the correlation matrix ggplot ( data = melt (correlation_matrix), aes ( x = Var1, y = Var2, fill = value)) +   geom_tile () +   theme_minimal () +   theme ( axis.text.x = element_text ( angle = 90 , vjust = 0.5 , hjust= 1 )) #The code loads the ggplot2 and reshape2 libraries and uses the cor function to calculate the correlation matrix of the mtcars dataset. Then, it creates a heatmap of the correlation matrix using ggplot, where the x and y axes represent the variable names and the fill represents the correlation value. The geom_tile() function is used to create the heatmap, while the theme_minimal() function is used to set the theme to a minimal design. Additionally, the theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1)) is used to rotate the x-axis text labels by ...

wk7

Image
  wk7.R 2023-02-22 library (gridExtra) library (ggplot2) p1 <- ggplot (mtcars, aes ( x = mpg, y = wt)) + geom_point () p2 <- ggplot (mtcars, aes ( x = mpg, y = disp)) + geom_point () p3 <- ggplot (mtcars, aes ( x = mpg, y = hp)) + geom_point () p4 <- ggplot (mtcars, aes ( x = mpg, y = drat)) + geom_point () p5 <- ggplot (mtcars, aes ( x = mpg, y = qsec)) + geom_point () p6 <- ggplot (mtcars, aes ( x = mpg, y = vs)) + geom_point () p7 <- ggplot (mtcars, aes ( x = mpg, y = am)) + geom_point () p8 <- ggplot (mtcars, aes ( x = mpg, y = gear)) + geom_point () p9 <- ggplot (mtcars, aes ( x = mpg, y = carb)) + geom_point () grid.arrange (p1, p2, p3, p4, p5, p6, p7, p8, p9, ncol = 3 ) Some of Few's recommendations surround the idea of clarity and ease of interpretation of data. In accordance to Few's recommendations, this visualisation could have had better axis labels, a consistent scale across each var...

wk 6

Image
  Wk6.R 2023-02-15 library (ggplot2) fatl = read.csv ( "Fatalities.csv" , stringsAsFactors = FALSE ) ggplot (fatl, aes ( x = state, y = fatal, fill = year)) + geom_bar ( stat = "identity" ) + theme ( axis.text.x = element_text ( angle = 90 , hjust   = 1 )) #this bar plot shows the total number of motor vehicle fatalities per state between 1982 and 1988. Few's and Yau's discussions on how to conduct basic visualization based on simple descriptive analysis emphasize the importance of selecting the appropriate chart type to best represent the data and the message that needs to be conveyed. They also stress the need to avoid clutter and to use color and labels effectively to enhance the chart's interpretability. This chart shows the states on the x axis and the fatalities on the y axis. The bars colored such that each bar will be split into shades of blue with represents the years. It is simple to understand that a single bar represents th...

wk 5

Image
  The graph that represents time and position data is a type of line graph that displays changes in an object's position over time. The horizontal axis represents time while the vertical axis represents the object's position. The plotted points on the graph represent the position of the object at specific moments in time, and the line connecting the points shows the overall trend in the object's motion over time. The slope of the line is used to determine the velocity of the object, and the acceleration can be calculated by finding the rate of change of the velocity over time.