【发布时间】:2016-04-10 19:00:49
【问题描述】:
我正在为与diamonds 非常相似的数据框创建一个 ggplotly。到目前为止,这是我所拥有的:
ggplotly(ggplot(diamonds, aes(depth, colour = cut)) +
geom_density() +
xlim(55, 70))
它创建以下内容:
当您将鼠标悬停在轨迹上时,它会显示:深度、切割和密度。我还想显示清晰,所以我添加了以下内容:
ggplotly(ggplot(diamonds, aes(depth, text = paste("Clarity: ", clarity), colour = cut)) +
geom_density() +
xlim(55, 70))
当我将鼠标悬停在曲线上时,它会显示深度、清晰度、切割和密度。这就是我想要的。但是,如何将密度保持为一条曲线,就像我创建的第一个图中一样,而不是多条曲线?
【问题讨论】:
-
尝试不使用
aes文本,但您必须写diamonds$clarity
标签: r ggplot2 plotly kernel-density