【发布时间】:2019-07-29 17:25:42
【问题描述】:
我想绘制一个添加了 geom_hline 的平面图并在图例中显示该线。但是,当我将线添加到图例时,所有条目都与构面数重复。
如何避免这种行为?
这是我的 MWE
library(shiny)
library(plotly)
library(ggplot2)
df <- mpg
# Define UI for application that draws a histogram
ui <- fluidPage(
mainPanel(
plotlyOutput('graph')
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
output$graph <- renderPlotly({
p <- ggplot2::mpg %>%
plot_ly %>%
ggplot() +
geom_point(aes(displ, hwy, color = class))
facet <- p + facet_wrap(~year)
facet + geom_hline(aes(yintercept = 20, linetype = 'hline20'), color = '#00b700') +
scale_linetype_manual(name = 'line', values = 1,
guide = guide_legend(aes = list(color = "#00b700")))
})
}
# Run the application
shinyApp(ui = ui, server = server)
【问题讨论】: