使用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)
的输出,其预期线型为:
来自ggplotly(static_plot)
的输出;没有考虑线型美学
# 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)
也许这很明显,但我找不到解决办法...