On génère une matrice à visualiser.
40
n <- 40
m <-
3
Q <- 2
L <-
c(0.3, 0.3, 0.4)
alpha <- c(0.4, 0.6)
beta <-
matrix(c(13, 21, 1, 25, 3, 16), nrow=Q, ncol=L)
lambda <-
matrix(0, nrow=n, ncol=Q)
z <- matrix(0, nrow=m, ncol=L)
w <- matrix(0, nrow=n, ncol=m)
x <-rownames(x) <- paste0("X", 1:nrow(x))
colnames(x) <- paste0("Y", 1:ncol(x))
cbind(1:n, sort(sample(Q, n, replace=TRUE, prob=alpha)))] <- 1
z[cbind(1:m, sort(sample(L, m, replace=TRUE, prob=beta)))] <- 1
w[ z%*%lambda%*%t(w)
a <- apply(z%*%lambda%*%t(w), c(1,2), FUN=function(x) rpois(1,x))
x <-
heatmap(x,
Colv=NA,
Rowv=NA,
add.expr = c(
abline(h = cumsum(colSums(z)) + 0.5, col = "grey20", lwd = 2),
abline(v = cumsum(colSums(w)) + 0.5, col = "grey20", lwd = 2)
),col=hcl.colors(12, "YlOrRd", rev = TRUE)
)
::image.plot(1:n, 1:m, t(x),
fieldscol = c(hcl.colors(12, "YlOrRd", rev = TRUE)),
xlab = "", ylab = "", axes = FALSE, zlim = c(min(x), max(x))
)abline(h = cumsum(colSums(z)) + 0.5, col = "grey20", lwd = 2)
abline(v = cumsum(colSums(w)) + 0.5, col = "grey20", lwd = 2)
axis(BELOW <- 1, at = 1:n, labels = as.factor(as.character(rownames(x))), las = 2, cex.axis = 0.6)
axis(LEFT <- 2, at = 1:m, labels = as.factor(as.character(colnames(x))), las = 2, cex.axis = 0.6)
::heatmap.2(x,
gplotsColv=FALSE,
Rowv=FALSE,
dendrogram="none",
trace="none",
add.expr=c(
abline(h = cumsum(colSums(z)) + 0.5, col = "grey20", lwd = 2),
abline(v = cumsum(colSums(w)) + 0.5, col = "grey20", lwd = 2)
),margins=c(5,5),
key = TRUE,
keysize = 2,
revC=TRUE,
col=hcl.colors(12, "YlOrRd", rev = TRUE)
)
which(x > 0)
indices <- min(x)
min <- max(x)
max <- reshape2::melt(x)
dfx <-
ggplot(dfx, aes(x=Var2, y=Var1, fill=value)) +
fig1 <- geom_tile() +
scale_fill_distiller(palette = "YlOrRd", direction = 1) +
theme(axis.text.x = element_text(size=rel(1), angle=90),
axis.text.y = element_text(size=rel(1))
+
) geom_vline(xintercept = cumsum(colSums(w)) + 0.5) +
geom_hline(yintercept = cumsum(colSums(z)) + 0.5)
fig1
ggplotly(fig1)
NULL
plotly_shapes <-for (i in cumsum(colSums(z))) {
c(plotly_shapes, list(list(type = "line",
plotly_shapes <-line = list(color = "black"), opacity = 0.8,
x0 = 0.5, x1 = m+0.5, xref = "x",
y0 = i + 0.5, y1 = i + 0.5, yref = "y")))
}for (i in cumsum(colSums(w))) {
c(plotly_shapes, list(list(type = "line",
plotly_shapes <-line = list(color = "black"), opacity = 0.8,
x0 = i+0.5, x1 = i+0.5, xref = "x",
y0 = +0.5, y1 = n+0.5, yref = "y")))
}plot_ly(dfx, x=~Var2, y=~Var1, z=~value) %>%
add_heatmap(colors = "YlOrRd") %>%
colorbar(title = "value") %>%
layout(shapes = plotly_shapes)
d3heatmap(x, Rowv = FALSE, Colv = FALSE, colors = "YlOrRd")
"https://images.plot.ly/plotly-documentation/images/heatmap-galaxy.jpg"
url <- tempfile()
tmpf <-download.file(url,tmpf,mode="wb")
readJPEG(tmpf)
data <- file.remove(tmpf)
fr <-
rowSums(data*255, dims = 2)
zdata =
plot_ly(
fig <-z = zdata,
colorscale = list(c(0,0.5,1),c("blue", "white", "red")),
type = "heatmapgl"
)
fig
ggplot(dfx, aes(x=value)) +
hist1 <- geom_histogram(binwidth=1, color="black", fill="orange")
ggplotly(hist1)
plot_ly(dfx,
hist2 <-x = ~value,
type = "histogram",
marker = list(color = "orange",
line = list(color = "black",width = 2)
)
)
hist2