Hi,
I try to make a heatmap with 2 bar charts corresponding to the sum of each line/column (code below) of the matrix. My result is not far away that I want but I have 3 questions about this:
- Is there a better way to define the layout of multiple figures ?
- Why do I have a point for the fucntion plotly_empty?
- How can I have colors that are function of quantitative variable in bar chart? The βcolorβ option give one color per bar as it was a qualitative variable. Do i just have to define a color palette according to data outside plot_ly function?
Thank you for your answers.
d β diamonds[sample(nrow(diamonds), 1000), ]
aaa β as.matrix(table(d$cut, d$clarity))
bbb β as.data.frame(apply(aaa, 1, sum))
colnames(bbb) β βcutβ
bbb$cl β rownames(bbb)
ccc β as.data.frame(apply(aaa, 2, sum))
colnames(ccc) β βclarityβ
ccc$cl β rownames(ccc)
p1 β plot_ly(z = aaa, x = colnames(aaa), y = rownames(aaa), type = βheatmapβ, colorbar = list(title = ββ), showscale = FALSE)
p2 β plot_ly(y = bbb$cl, x = bbb$cut, type = βbarβ, orientation = βhβ, color = bbb$cl, showlegend = FALSE)
p3 β plot_ly(y = ccc$clarity, x = ccc$cl, type = βbarβ, orientation = βvβ, group = ccc$clarity, showlegend = FALSE)
pvid β plotly_empty()
subplot(p3, pvid, p1, p2, nrows = 2) %>% layout(
yaxis = list(domain = c(0.90, 1), title = ββ),
xaxis = list(domain = c(0, 0.85), title = ββ, showticklabels = FALSE),
yaxis2 = list(domain = c(0.90, 1), title = ββ),
xaxis2 = list(domain = c(0.90, 1), title = ββ),
yaxis3 = list(domain = c(0, 0.85), title = ββ),
xaxis3 = list(domain = c(0, 0.85), title = ββ),
yaxis4 = list(domain = c(0, 0.85), title = ββ, showticklabels = FALSE),
xaxis4 = list(domain = c(0.90, 1), title = ββ)
)