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]))
それが唯一の2つの選択肢が表示されますが、もし1つの選択肢しか選択されていない場合は、軸タイトル上でNAが選択されます。
私はそれが動的になりたいので、ユーザーはyaxisのタイトルが調整される1つ以上の選択肢を選ぶことができます。
ありがとうございました!
感謝を試してみては変更される必要があるのは!私は必要なもの厥場合 –