1
私のコードはほぼ完成しましたが、もう少し小さな問題があります。ドロップダウンメニューからの入力に応じてx軸とy軸を変更する必要があります。たとえば、x = Salesの場合、y = R & Dの場合、x軸は「Sales(million)$」、y軸は「R & D(millions $)」などとなります。しかし、y軸はSalesで、x軸はR & Dでも構いません。これは私を混乱させます。ここに私のコードは、これまでです:ggplot2複数の軸のタイトル
UI:
ui = dashboardPage(
dashboardHeader(title = "Apple Financials"),
dashboardSidebar(
fileInput("file1", label = "Upload SAS Data:", accept = ".sas7bdat"),
selectInput("x", label = "X-Axis Variable", choices = c("Sales" = "SALEQ", "Cash" = "CHEQ", "Assets" = "ATQ", "Profits" = "OIADPQ", "R&D" = "XRDQ", "SG&A" = "XSGAQ")),
selectInput("y", label = "Y-Axis Variable", choices = c("Sales" = "SALEQ", "Cash" = "CHEQ", "Assets" = "ATQ", "Profits" = "OIADPQ", "R&D" = "XRDQ", "SG&A" = "XSGAQ"), selected = "XRDQ"),
selectInput("scale", label = "Choose the Scale:", choices = c("Levels" = "identity", "Log 10" = "log10")),
radioButtons("model", label = "Choose the Model:", choices = c("Linear Model" = "lm", "LOESS" = "loess", "Robust Linear" = "rlm", "None"), selected = "loess"),
checkboxInput("ribbon", label = "Standard Error Ribbon", value = TRUE),
conditionalPanel(
condition = "input.model == 'loess'",
sliderInput("span", label = "Span for LOESS", min = 0, max = 1, value = .75)
)
),
dashboardBody(
box(width = NULL, height = 415, plotOutput("plots"))
)
)
はサーバー:input$x
とinput$y
は、両方の文字列
server = function(input, output) {
output$plots = renderPlot({
data = input$file1
if(is.null(data))
return(NULL)
df = read_sas(data$datapath)
ggplot(df, aes_string(x = input$x, y = input$y)) +
geom_point(size = 2) +
geom_smooth(method = input$model, span = input$span, se =
input$ribbon) +
scale_x_continuous(trans = input$scale) +
scale_y_continuous(trans = input$scale) +
theme_minimal() +
validate(
need(input$x != input$y,
paste("X and Y variables have to be different"))
)
})
}
shinyApp(ui, server)
ありがとうございます!だから、私がそれをすると、例えば "SALEQ(millions $)"が印刷されますが、実際の変数名の代わりに "Sales"と言いたいです。 – Tarzan
@Tarzan私の編集を参照してください。あなたの質問は再現性がなく、shinyAppでは公平ではありませんので、私はそれをテストすることはできません。だからそれ以上の問題があれば教えてください。 – useR