在y轴上增加文本和标题之间的距离在绘图中不起作用

时间:2018-04-14 13:23:52

标签: r ggplot2 shiny ggplotly

你好我已经创建了一个闪亮的应用程序,其中包括一个用图表创建的散点图。我的问题是,尽管使用基于Increase dustance between text and title on the y-axisaxis.title.y = element_text(margin = margin(t = 0, r = 20, b = 0, l = 20)),但我无法增加轴标题(y)和轴标签之间的空间 。每次更改输入时都会更新绘图,因此每次都会更改轴标题和标签。

 #ui.r
    library(shiny)
    library(ggplot2)
    library(plotly)
    fluidPage(

      # App title ----
      titlePanel(div("CROSS CORRELATION",style = "color:blue")),

      # Sidebar layout with input and output definitions ----
      sidebarLayout(

        # Sidebar panel for inputs ----
        sidebarPanel(



        ),
        # Main panel for displaying outputs ----
        mainPanel(

          tabsetPanel(type = "tabs",
                      tabPanel("Table",
                               shiny::dataTableOutput("contents")),
                      tabPanel("Correlation Plot",
                               fluidRow(
                                 column(3, uiOutput("lx1")),
                                 column(3,uiOutput("lx2"))),
                               hr(),
                               fluidRow(
                                 plotlyOutput("sc"))
                      ))
          )))
    #server.r
    function(input, output) {


      output$contents <- shiny::renderDataTable({

        iris
      })


      output$lx1<-renderUI({
        selectInput("lx1", label = h4("Select 1st Expression Profile"), 
                    choices = colnames(iris[,1:4]), 
                    selected = "Lex1")
      })
      output$lx2<-renderUI({
        selectInput("lx2", label = h4("Select 2nd Expression Profile"), 
                    choices = colnames(iris[,1:4]), 
                    selected = "Lex2")
      })


      output$sc<-renderPlotly({

        p1 <- ggplot(iris, aes_string(x = input$lx1, y = input$lx2))+

          # Change the point options in geom_point
          geom_point(color = "darkblue") +
          # Change the title of the plot (can change axis titles
          # in this option as well and add subtitle)
          labs(title = "Cross Correlation") +
          # Change where the tick marks are
          scale_x_continuous(breaks = seq(0, 2.5, 30)) +
          scale_y_continuous(breaks = seq(0, 2.5, 30)) +
          # Change how the text looks for each element
          theme(title = element_text(family = "Calibri", 
                                     size = 10, 
                                     face = "bold"), 
                axis.title = element_text(family = "Calibri Light", 
                                          size = 16, 
                                          face = "bold", 
                                          color = "darkgrey"), 
                axis.text = element_text(family = "Calibri", 
                                         size = 11),
                             axis.title.y = element_text(margin = margin(t = 0, r = 20, b = 0, l = 20))
)+
          theme_bw()+
          geom_smooth(method = input$td)+
          annotate("text", x = 10, y = 10, label = as.character(input$an))
        ggplotly(p1) %>%
          layout(hoverlabel = list(bgcolor = "white", 
                                   font = list(family = "Calibri", 
                                               size = 9, 
                                               color = "black")))

      }) 




    }

0 个答案:

没有答案