我的目标是将点与多个图例属性相关联,以帮助用户主动筛选图形进行比较。例如,我试图将代码中的每个点与其DP及其描述独立地关联起来。这样,我可以隐藏除DP1点之外的所有点,或者只显示测试一的结果。相反,我的代码使每个点作为其因素的组合而具有唯一性。谢谢你的帮助!
这是我的尝试。
library(tidyverse)
library(plotly)
df = read.csv("C:/Users/nicho/Documents/R/Test.csv")
output = df %>%
ggplot(df,mapping = aes(Wave,Score,col = factor(Level),
text = paste("DP:",DP,"<br>",
"Wave:",Wave,"<br>",
"Level:",Level,"<br>",
"Score:",Score,"<br>",
"Desc:",Desc
)
))+
geom_line(mapping = aes(group = DP))+
geom_point(mapping = aes(col =factor(DP),shape = factor(Desc)))+
facet_grid(~Location)
font = list(
size = 15,
color = "white"
)
label = list(
bgcolor = "#232F34",
bordercolor = "transparent",
font = font
)
ggplotly(output, tooltip = c("text")) %>%
style(hoverlabel = label) %>%
layout(font = font)
输出
这是我最终为任何遇到这种情况的人找到的解决方案,我试图像这样过滤我的图形结果…
library(shinydashboard)
library(shiny)
#______________________________________________________________________________#
server <- function(input, output, session) {
df <- reactive({
subset(iris, Petal.Width == input$Petalw)
})
# Extract list of Petal Lengths from selected data - to be used as a filter
p.lengths <- reactive({
unique(df()$Petal.Length)
})
# Filter based on Petal Length
output$PetalL <- renderUI({
selectInput("PetalLengthSelector", "PetalLength", as.list(p.lengths()))
})
# Subset this data based on the values selected by user
df_1 <- reactive({
foo <- subset(df(), Petal.Length == input$PetalLengthSelector)
return(foo)
})
output$table <- DT::renderDataTable(
DT::datatable(df_1(), options = list(searching = FALSE,pageLength = 25))
)
###JUNK
output$correlation_plot <- renderPlot({
plot(df_1()$Petal.Length, df_1()$Petalw,
xlab = "Length", ylab = "Width")
})
}
#______________________________________________________________________________#
ui <- navbarPage(
title = 'Select values in two columns based on two inputs respectively',
fluidRow(
column(width = 12,
plotOutput('correlation_plot')
)
),
fluidRow(
column(width = 3,
selectInput("Petalw","PetalWidth", choices = unique(iris$Petal.Width),multiple = T),
uiOutput("PetalL")
),
column(9,
tabPanel('Table', DT::dataTableOutput('table'))
)
)
)
shinyApp(ui, server)