Load the (movies) data set from the BristolVis R package. The data can be called and viewed using:

data(bmov, package = "BristolVis")
head(bmov)

Scatter plots (15 minutes)

Let's start with some simple scatter plots using the bmov data:

  1. Plot length Vs. rating using the advanced graphics package (ggplot2):
require(ggplot2)
require(plotly)
(G = ggplot(bmov, aes(Length, Rating)) + geom_point())
  1. Use the cut function to generate a categorical form of the variable Year with sensible cutpoints.
summary(bmov$Year)
bmov$cat_timing = cut(bmov$Year, breaks = c(1930, 1990, 2000, 2005))
  1. Plot length Vs. rating such that points are coloured using categories of your generated timing:
(G = ggplot(bmov, aes(Length, Rating, color = cat_timing)) + geom_point())
  1. The default colors of the previous plot are terrible! use your own color selections to generate a better plot.
(G = G + scale_color_manual(values = c("blue", "yellow", "red")))
  1. Generate an interactive plot of the plot in (4) using the plotly package and name it Fig_scatter
Fig_scatter = ggplotly(G)
  1. Try to zoom in using your mouse by box selection to explore further detailed information

  2. Save your interactive plot as an html file.

htmlwidgets::saveWidget(Fig_scatter, "Fig_scatter.html")

Histograms (10 minutes)

  1. Use the ggplot2 to plot a histogram of the movie years restricted to data after 1980.
(G = ggplot(bmov[bmov$Year>=1980,], aes(Year)) + geom_histogram())
  1. Produce the same plot as in (1), but set the number of bins to 25.
(G = G + geom_histogram(bins = 25))
  1. Generate an interactive plot of the plot in (2) using the plotly package and name it Fig_hist
Fig_hist = ggplotly(G)
  1. Try to zoom in using your mouse by box selection to explore further detailed information and reset the plot (double-click)

  2. Save your interactive plot as an html file.

htmlwidgets::saveWidget(Fig_hist, "Fig_hist.html")

Boxplots (10 minutes)

  1. Generate a boxplot for the ratings data by generated categories of production timing using ggplot2.
(G = ggplot(bmov, aes(x=cat_timing, y =Rating)) + geom_boxplot(aes(group = cat_timing)))
  1. Try generating a similar interactive boxplot
Fig_box = ggplotly(G)
  1. save the interactive plot to an html file
htmlwidgets::saveWidget(Fig_box, "Fig_box.html")

Corrlation matrix (20 minutes)

  1. Use the built-in iris data to compute a correlation matrix and correlation p-values for the continous (first four) variables
data(iris)
head(iris)
require(ggcorrplot)
data_cont = iris[,1:4]
Corr = cor(data_cont)
corr.p = cor_pmat(data_cont)
  1. Visualize the correlation matrix using the method = "circle"
(G = ggcorrplot(Corr, method = "circle"))
  1. Show the lower triangle using hierarchical clustering and square method rather than circle.
(G = ggcorrplot(Corr, hc.order = TRUE, type = "lower"))
  1. Use correlation significance level 0.01 to highlight the non-significant coefficient
(G = ggcorrplot(Corr, hc.order = TRUE, type = "lower", p.mat = corr.p, sig.level = 0.01))
  1. Use different shape - rather than the cross - to highlight the non-significant coefficient (use help of the function ggcorrplot by typing: ?ggcorrplot to find out)
(G = ggcorrplot(Corr, hc.order = TRUE, type = "lower", p.mat = corr.p, sig.level = 0.01, pch = 10))
  1. Add coeficient values on the plot in (3)
(G1 = ggcorrplot(Corr, hc.order = TRUE, type = "lower", lab = TRUE, lab_size = 3))

7.Produce interactive plot of the plot in (6)

Fig_cor = ggplotly(G1)

7.save the interactive plot in as html.

htmlwidgets::saveWidget(Fig_cor, "Fig_cor.html")


statcourses/BristolVis documentation built on Jan. 31, 2021, 9:24 p.m.