library(plotly)
library(corrr)
library(RColorBrewer)
library(corrplot)
#select numeric columns
index=sapply(iris, is.numeric)
iris_numeric<-iris[index==TRUE]
#p.mat <- cor.mtest(iris_numeric)$p
p.mat <- corrr::correlate(iris_numeric)%>%as_matrix()
iris_numeric%>%cor()%>%corrplot::corrplot( method = "color",order = "hclust",p.mat = p.mat, sig.level = 0.01,insig = "label_sig", pch.col = "white",col = brewer.pal(n = 11, name = "PuOr"))
Fig. 30
z=iris[index==TRUE]%>%cor( )
p <- plot_ly(z = z, type = "heatmap")
p
Fig. 30
M <- cor(iris_numeric)
corrplot.mixed(M,upper = "color", tl.col = "black")
Fig. 30
iris_numeric%>%cor()%>%corrplot::corrplot()
Fig. 30
iris_numeric%>%corrr::correlate()%>%corrr::fashion()
## rowname Sepal.Length Sepal.Width Petal.Length Petal.Width
## 1 Sepal.Length -.12 .87 .82
## 2 Sepal.Width -.12 -.43 -.37
## 3 Petal.Length .87 -.43 .96
## 4 Petal.Width .82 -.37 .96
iris_numeric%>%corrr::correlate()%>%corrr::network_plot()
Fig. 30
library(ggplot2)
library(plotly)
library(reshape)
library(Hmisc)
library(viridis)
x <- iris_numeric
y <- as.matrix(x)
r <- rcorr(y)
m1 <- melt(r$r)
m2 <- melt(r$P)
p.value <- m2$value
p <- ggplot(m1, aes(X1, X2, fill = value, label=p.value)) + geom_tile() +
labs(x="",y="")+
scale_fill_viridis()
ggplotly(p)
Fig. 30
pacman::p_load(networkD3)
library(networkD3)
data(MisLinks, MisNodes)
head(MisLinks, 3)
## source target value
## 1 1 0 1
## 2 2 0 8
## 3 3 0 10
head(MisNodes, 3)
## name group size
## 1 Myriel 1 15
## 2 Napoleon 1 20
## 3 Mlle.Baptistine 1 23
forceNetwork(Links = MisLinks, Nodes = MisNodes, Source = "source",
Target = "target", Value = "value", NodeID = "name",
Group = "group", opacity = 0.9, Nodesize = 3,
linkDistance = 100, fontSize = 20)
Fig. 30
library(crosstalk)
sd <- SharedData$new(txhousing, ~city)
p <- ggplot(sd, aes(date, median)) + geom_line()
gg <- ggplotly(p, tooltip = "city")
# Persistent mode can still be enabled in this case by holding the
# shift key when hovering over lines
highlight(gg, on = "plotly_hover", dynamic = TRUE)
Fig. 30
# Persistent mode can be set permanently like so
highlight(gg, on = "plotly_hover", dynamic = TRUE, persistent = TRUE)
Fig. 30
d <- SharedData$new(iris)
p <- GGally::ggpairs(d, aes(color = Species), columns = 1:4)
highlight(ggplotly(p), on = "plotly_selected")
Fig. 30
# Group name is used to populate a title for the dropdown
sd <- SharedData$new(txhousing, ~city, group = "Choose a city")
plot_ly(sd, x = ~date, y = ~median) %>%
group_by(city) %>%
add_lines(text = ~city, hoverinfo = "text") %>%
highlight(on = "plotly_hover", persistent = TRUE, selectize = TRUE)
Fig. 30
# if you don't want to highlight individual points, you could specify
# `class` as the key variable here, instead of the default (rownames)
m <- SharedData$new(mpg)
p <- ggplot(m, aes(displ, hwy, colour = class)) +
geom_point() +
geom_smooth(se = FALSE, method = "lm")
ggplotly(p) %>% highlight("plotly_hover")
Fig. 30
# for better tick labels
mtcars$am <- dplyr::recode(mtcars$am, `0` = "automatic", `1` = "manual")
# choose a model by AIC stepping backwards
mod <- step(lm(mpg ~ ., data = mtcars), trace = FALSE)
# produce diagnostic plots, coloring by automatic/manual
pm <- GGally::ggnostic(mod, mapping = aes(color = am))
# ggplotly() automatically adds rownames as a key if none is provided
ggplotly(pm) %>% highlight("plotly_click")
Fig. 30
m <- SharedData$new(mpg)
p1 <- ggplot(m, aes(displ, fill = class)) + geom_density()
p2 <- ggplot(m, aes(displ, hwy, fill = class)) + geom_point()
ggplotly(p1) %>% highlight("plotly_hover")
Fig. 30
ggplotly(p2) %>% highlight("plotly_hover")
Fig. 30
#subplot(p1, p2) %>% highlight("plotly_click") %>% hide_legend()