【发布时间】:2020-02-04 09:59:50
【问题描述】:
我正在尝试创建一个包含 Plots 的 Shiny Dashboard。 Plotly 是一个很棒的包,它为用户提供了很好的可视化和交互性。但是当我使用 ggplotly 将我的 ggplot 图转换为交互式图表时,我没有得到预期的输出,并且当输出中的方面数量更多时,问题会成倍增加。例如,请找到下面的代码。
Source_Data_dupli <-
data.frame(
key = c(1, 1, 1, 2, 2, 2, 3, 3, 3,4,4,5,5,6,7),
Product_Name = c(
"Table",
"Table",
"Chair",
"Table",
"Bed",
"Bed",
"Sofa",
"Chair",
"Sofa",
"Table",
"Bed",
"Chair",
"Table",
"Bed",
"Bed"
),
Product_desc = c("XX", "XXXX", "YY", "X", "Z", "ZZZ", "A", "Y",
"A","Y","XX", "XXXX", "YY", "X", "Z"),
Cost = c(1, 2, 3, 4, 2, 3, 4, 5, 6, 7,6,8,9,12,34)
)
用于生成图表的代码
ggplotly(Source_Data_dupli %>%
ggplot(aes(Product_Name, Cost)) +
geom_col(aes(fill = Product_desc), position = position_dodge(preserve =
"single")) +
facet_wrap(~key, scales = "free_x", strip.position = "bottom") +
theme(strip.placement = "outside"))
这是我不使用 ggplotly 时的输出
这是 ggplotly。
我在使用 ggplotly 时遇到的问题是
- 轴和图例值被删除。
- 我们可以很清楚地看到第二行的图表被挤压并且看起来不太好的区别。
有没有办法克服这个特殊的问题?我也将在闪亮的仪表板中使用这些图表。请让我知道您的建议。
提前致谢。
大卫
【问题讨论】:
标签: r ggplot2 shiny plotly ggplotly