【发布时间】:2021-02-16 20:13:18
【问题描述】:
在 Rshiny 中,线图在图的右上角显示迹线 0 和迹线 1。单击第 0 行使该行消失,而单击 Trace 1 使该行顶部的文本消失。代码如下。
ui <- fluidPage(plotlyOutput("fig1"))
server <- function(input, output) {
Primates <- c('Potar monkey', 'Gorilla', 'Dinosaur', 'Rhesus monkey', 'Chimp')
Bodywt <- c('a', 'b', 'c', 'd', 'e')
Brainwt <- c(115, 406, 1320, 179, 440)
data <- data.frame(Primates, Bodywt, Brainwt)
fig <- plot_ly(data, x = ~Bodywt, y = ~Brainwt, type = 'scatter', mode = 'lines')
fig <- fig %>% add_text(text = data$Primates, textposition = 'top', textfont = list(color = '#000000', size = 16))
fig <- fig %>% layout(title = 'Primates Brain and Body Weight',
xaxis = list(title = 'Body Weight (kg)',
zeroline = TRUE),
yaxis = list(title = 'Brain Weight (g)',
range = c(0,1400)))
output$fig1 <- renderPlotly(fig)
}
shinyApp(ui,server)
我需要一些帮助来删除 Trace 0 和 Trace 1。
【问题讨论】:
-
您要删除图例还是链接图例项(两条迹线并行隐藏)?
标签: r shiny plotly trace r-plotly