[R] Layout of multiple figures + Bar charts colors function of quantitative data

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 = β€œβ€)
)