【发布时间】:2016-03-28 02:51:18
【问题描述】:
我正在用ggplotly() 制作一些数字,并注意到facet_wrap 和facet_grid 会导致图例中的每个项目都按面数重复。有没有办法阻止这种情况?
例如:
library("ggplot2")
library("plotly")
diamonds = diamonds[diamonds$cut %in% c("Fair", "Good"),]
dia = ggplot(diamonds, aes(x = cut)) +
geom_bar(aes(stat = "identity", fill = cut)) +
facet_grid(.~color)
ggplotly(dia)
?plotly 文档不是很详细,these 都没有图例。
当我输入 ggplotly 时会出现以下情况:
function (p = ggplot2::last_plot(), filename, fileopt, world_readable = TRUE)
{
l <- gg2list(p)
if (!missing(filename))
l$filename <- filename
if (!missing(fileopt))
l$fileopt <- fileopt
l$world_readable <- world_readable
hash_plot(p$data, l)
}
【问题讨论】:
-
我认为这是按预期工作的。见Coordinating Color Across Subplots。看起来颜色映射将应用于每个 x 轴。在这种特定情况下,不需要刻面。一个更严重的错误是 Plotly 图表的 y 值与 ggplot 图表中的不同。但是对于 geom_point 类型,它们是相同的。
-
@VanceLopez 是的,我明白你的意思。所以现在我同意它“正常”工作,但对于像我的例子这样的情况绝对不是想法(我同意这不是必需的,但只是可以使用的东西)。
-
@VanceLopez 我什至没有注意到 plotly 和 ggplot y 值之间的差异。不错的收获。但是怎么办?