1
我試圖製作一個包含矩形的圖。我使用ggplot2創建它們,並希望通過將它們轉換爲繪圖對象來「使它們交互」。 現在的問題是,轉換到plotly似乎鬆動ggplot2中指定的矩形顏色。將ggplot2彩色矩形轉換爲灰色
這裏是一個小的自我解釋的代碼示例:
test.dat <- data.frame(xmin=c(0,1.5), ymin=c(-1,-1), xmax=c(1,2), ymax=c(1,1), col=c("blue", "red"))
ggp.test <- ggplot() + geom_rect(data=test.dat, aes(xmin=xmin, ymin=ymin, xmax=xmax, ymax=ymax), fill=test.dat$col) + theme_bw()
ggp.test
ply.test <- plotly_build(ggp.test)
ply.test
有趣的是,當我像下面指定懸停信息,然後顏色是正確的:
test.dat <- data.frame(xmin=c(0,1.5), ymin=c(-1,-1), xmax=c(1,2), ymax=c(1,1), col=c("blue", "red"), hovinf=c("rec1", "rec2"))
ggp.test <- ggplot() + geom_rect(data=test.dat, aes(xmin=xmin, ymin=ymin, xmax=xmax, ymax=ymax, text=paste("hoverinfo:", hovinf)), fill=test.dat$col) + theme_bw()
ply.test <- plotly_build(ggp.test)
ply.test
任何人可以解釋這種現象?
感謝您的簡單和明確的解釋!我現在可以看到問題出在哪裏。 –