ggplotly忽略geom_bar的“线型”美学

时间:2019-11-13 11:30:30

标签: r ggplot2 geom-bar ggplotly aesthetics

使用ggplot2 plotly::ggplotly时如何使geom_bar正确渲染/打印线型?

这是一个可繁殖的例子:

library(tidyverse)
library(plotly)

# this shows the problem
static_plot = ggplot(data = mtcars, aes(x = rownames(mtcars), y = mpg, linetype=as.character(cyl))) +
  geom_bar(stat = "identity", fill = NA, color = "black")
print(static_plot) # see that here we have different linetypes as expected

ggplotly(static_plot) # the lines are all the same i.e continuous!

来自print(static_plot)的输出,其预期线型为:

output from print() with expected linetypes

来自ggplotly(static_plot)的输出;没有考虑线型美学

ouput from <code>ggplotly()</code>

# using a geom_line it works fine
static_plot2 = ggplot(data = mtcars, aes(x = disp, y = mpg, linetype=as.character(cyl))) +
  geom_line(color = "black")
print(static_plot2)

ggplotly(static_plot2)

working example with geom_line

也许这很明显,但我找不到解决办法...

0 个答案:

没有答案