0
我想調整y軸標題爲ggplot
。我選擇了selectizeInput
小部件,以便用戶可以選擇多列進行繪圖。我希望y軸的標題改變動態並顯示選擇列名。閃亮的ggplot:動態y軸標題(多列)
有了這個簡單的代碼:
library(shiny)
library(DT)
library(ggplot2)
library(reshape2)
x <- as.numeric(1:1000000)
y <- as.numeric(1:1000000)
z <- as.numeric(1:1000000)
data <- data.frame(x,y, z)
shinyApp(
ui = fluidPage(selectizeInput(inputId = "yaxis",
label = "Y-axis",
choices = list("x","y","z"),
selected = c("x"), multiple=TRUE),
dataTableOutput('tableId'),
plotOutput('plot1')),
server = function(input, output) {
output$tableId = renderDataTable({
datatable(data, options = list(pageLength = 10, lengthMenu=c(10,20,30)))
})
output$plot1 = renderPlot({
filtered_data <- data[input$tableId_rows_all,]
widedata <- subset(filtered_data, select=c("x", input$yaxis))
longdata <- melt(widedata, id.vars="x", variable.name="Variables", value.name="Value_y")
ggplot(data=longdata, aes_string(x="x",y="Value_y",group="Variables")) + geom_line() +ylab(paste(input$yaxis))
})
}
)
它是隻顯示第一選擇......
如果我更改爲:
+ylab(paste(input$yaxis[1],input$yaxis[2]))
它顯示只有兩個選擇,但如果只有一個選擇,然後在軸標題上,我們將看到不適用代替第二選擇。
我希望它是動態的,所以用戶可以選擇1個或更多的選擇,yaxis的標題將要調整..
感謝您的幫助!
謝謝!這就是我需要什麼 –