【发布时间】:2017-02-14 09:53:26
【问题描述】:
我试图制作一个包含矩形的图。我正在使用 ggplot2 创建它们,并希望通过将它们转换为绘图对象来“使它们具有交互性”。 现在的问题是,转换为 plotly 似乎失去了 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
谁能解释这种现象?
【问题讨论】: