我在R-shiny网页上工作。因为我想绘制散点图x对y,X作为状态名称,y作为数据点。因为它显示水平线而不是点。如何解决这个问题呢 ? I want scatter plot instead of horizontal lines , i don't understand why it shows this kind of plot先谢谢你。
ui.R
library(shiny)
shinyUI(fluidPage( titlePanel("Multivariable plot"),
sidebarLayout(
sidebarPanel(
fileInput("file", label = h3("Select CSV File")),
checkboxInput(inputId = 'header', label = 'col names', value = TRUE),
radioButtons(inputId = 'sep', label = 'Seperator', choices = c("comma"=',',"semi comma"=';'), selected = ','),
#checkboxGroupInput("choices1", label = h3("Wybierz Kolumny"), choices = NULL),
# there is combobox to pick column
selectInput("combobox", label = h3("x var"),choices = NULL),
#selectInput("combobox1", label = h3("y var"),choices = NULL)
selectizeInput("combobox1", label = h3("y var"), choices = NULL ,multiple = TRUE )
),
mainPanel(
uiOutput("tb")
)
)
))
Server.R
library(ggplot2)
function(input, output, session){
data <- reactive({
file1 <- input$file
if(is.null(file1)){return()}
dataSet <- read.csv(file=file1$datapath, sep=input$sep, header = input$header )
#updateCheckboxGroupInput(session, "choices1", choices = colnames(dataSet))
# this line updates selection in combobox
updateSelectInput(session, "combobox", choices = colnames(dataSet))
updateSelectizeInput(session, "combobox1", choices = colnames(dataSet), server = TRUE)
dataSet
})
output$table <- renderTable({
if(is.null(data())){return ()}
data()
})
output$multivarplot <- reactivePlot(function(){
x <- data()[, input$combobox]
ydat <- data.frame(data()[, input$combobox1])
xval<-data.frame(x,ydat)
# ggplot(xval, aes(x = reorder(x, -x), y = y))+geom_point(colour='red')
#g= ggplot(xval, aes(x,ydat[,1]))+geom_point(colour='red')
ny <- ncol(ydat)
# par(mar = c(3,3, 3, .31))
# par(mar=c(5.1,4.1,4.1,2.1))
par(mfcol=c(12,12),mfrow=c(1,1))
#plot(x,ydat[,1],col ='red')
if(ny==1)
# g= ggplot(xval, aes(x,ydat[,1]))+geom_point(colour='red')
# g
# #
plot(x,ydat[,1],type = "p")
else
if(ny==2)
# { g= ggplot(xval, aes(x,ydat[,1]))+geom_point(colour='red')
# r=g+ggplot(xval, aes(x,ydat[,2]))+geom_point(colour='blue')
# r
# }
{ y1 <- ydat[,1]
y2 <- ydat[,2]
plot(x, y1, ylim = range(c(y1,y2)),colour='red')
points(x,y2)}
# req(is.numeric(x))
#plot(x,y, col = 'blue', border = 'white')
})
output$tb <- renderUI({
tabsetPanel(tabPanel("Table", tableOutput("table")),
tabPanel("Plot",
plotOutput("multivarplot")))
})
}