Load the (movies) data set from the BristolVis
R package. The data can be called and viewed using:
data(bmov, package = "BristolVis") head(bmov)
Let's start with some simple scatter plots using the bmov
data:
require(ggplot2) require(plotly) (G = ggplot(bmov, aes(Length, Rating)) + geom_point())
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))
(G = ggplot(bmov, aes(Length, Rating, color = cat_timing)) + geom_point())
(G = G + scale_color_manual(values = c("blue", "yellow", "red")))
plotly
package and name it Fig_scatter
Fig_scatter = ggplotly(G)
Try to zoom in using your mouse by box selection to explore further detailed information
Save your interactive plot as an html file.
htmlwidgets::saveWidget(Fig_scatter, "Fig_scatter.html")
ggplot2
to plot a histogram of the movie years restricted to data after 1980.(G = ggplot(bmov[bmov$Year>=1980,], aes(Year)) + geom_histogram())
(G = G + geom_histogram(bins = 25))
plotly
package and name it Fig_hist
Fig_hist = ggplotly(G)
Try to zoom in using your mouse by box selection to explore further detailed information and reset the plot (double-click)
Save your interactive plot as an html file.
htmlwidgets::saveWidget(Fig_hist, "Fig_hist.html")
ggplot2
.(G = ggplot(bmov, aes(x=cat_timing, y =Rating)) + geom_boxplot(aes(group = cat_timing)))
Fig_box = ggplotly(G)
htmlwidgets::saveWidget(Fig_box, "Fig_box.html")
iris
data to compute a correlation matrix and correlation p-values for the continous (first four) variablesdata(iris) head(iris) require(ggcorrplot) data_cont = iris[,1:4] Corr = cor(data_cont) corr.p = cor_pmat(data_cont)
(G = ggcorrplot(Corr, method = "circle"))
square
method rather than circle.(G = ggcorrplot(Corr, hc.order = TRUE, type = "lower"))
(G = ggcorrplot(Corr, hc.order = TRUE, type = "lower", p.mat = corr.p, sig.level = 0.01))
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))
(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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.