1
我幾乎完成了我的代碼,但我還有一個小問題。我需要根據下拉菜單中的輸入更改x和y軸。例如,如果x = Sales,則任何y = R & D,則x軸應該是「Sales(百萬美元)」,並且y軸應該是「R &D(百萬美元)」等等。但是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"))
)
)
服務器:
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(百萬美元)」,但我希望它說「銷售」,而不是實際的變量名稱 – Tarzan
@Tarzan查看我的編輯。由於你的問題是不可重複的,對於一個shinyApp來說這很公平是很難的,所以我無法測試它。所以請讓我知道是否還有其他問題。 – useR