【发布时间】:2016-05-11 10:15:11
【问题描述】:
将ggplotly() 用于ggplot 图形时遇到问题:y 轴消失。这是一个使用iris 数据集的可重现示例(这个示例非常垃圾,但无论如何)
data(iris)
g = ggplot(data = iris, aes(x = Petal.Length, y = Petal.Width, fill = Species)) +
geom_bar(stat = "identity", position = "dodge") +
scale_fill_manual(name = "legend", values = c("blue", "red", "green")) +
ylab("Y title") +
ylim(c(0,3)) +
xlab("X title") +
ggtitle("Main title")
g
ggplotly(g)
如您所见,Y 轴标题消失了。
好吧,如果 ylim 被删除它可以工作,但我想指定 y 限制。
我尝试执行以下操作:
data(iris)
g = ggplot(data = iris, aes(x = Petal.Length, y = Petal.Width, fill = Species)) +
geom_bar(stat = "identity", position = "dodge") +
scale_fill_manual(name = "legend", values = c("blue", "red", "green")) +
scale_y_continuous(name = "Y title", limits = c(0, 3)) +
xlab("X title") +
ggtitle("Main title")
g
ggplotly(g)
但现在是传说标题不合适了。
我的配置:R 3.2.0,plotly 2.0.16,ggplot2 2.0.0
在这两个例子中,ggplot 给出的图表是我想要的,但 ggplotly 给出了别的东西。这是一个问题,有解决方法吗?
【问题讨论】:
标签: r ggplot2 plotly ggplotly r-plotly