我用ggplot2创建了一个图,并想用plottly将其发布到我的Shiny App中。不幸的是,图例的位置没有被采用。此外,图例中的每个条目都会添加一个1,并且该图的标题也会消失。
我的情节的一部分
plot = ggplot() +
geom_bar(data = pi_plot, aes(x = as.Date(Month), y = value, fill = Domain), position = "stack", stat = "identity") +
geom_line(data = pi_fc_ly_plot, aes(x = as.Date(Month), y = value, group = PI, colour = PI), size = 0.75) +
theme(legend.title = element_blank()) +
labs(title = "Traffic",
subtitle = "Visits",
y = "Pageviews",
x = "Month",
caption = "Source: Google Analytics") +
scale_x_date(labels = date_format("%B"),
date_breaks = "month",
expand = c(0, 0)) +
scale_y_continuous(legend.position = "bottom")
在应用中调用绘图
ggplotly(plot)
答案 0 :(得分:0)
我前段时间做了类似的事情。我指定了传奇位置作为我的一部分 ggplotly函数调用,而不是我的ggplot函数调用。您可以尝试如下修改您的代码,看看它是否有效
plot = ggplot() +
geom_bar(data = pi_plot, aes(x = as.Date(Month), y = value, fill = Domain), position = "stack", stat = "identity") +
geom_line(data = pi_fc_ly_plot, aes(x = as.Date(Month), y = value, group = PI, colour = PI), size = 0.75) +
theme(legend.title = element_blank()) +
labs(title = "Traffic",
subtitle = "Visits",
y = "Pageviews",
x = "Month",
caption = "Source: Google Analytics") +
scale_x_date(labels = date_format("%B"),
date_breaks = "month",
expand = c(0, 0))
ggplotly(plot) %>% layout(legend = list(orientation = "h", y=-0.5))
我不知道您的字幕问题的出处。