Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 覆盖几何多边形中的填充颜色_R_Shiny_Polygon_Aesthetics - Fatal编程技术网

R 覆盖几何多边形中的填充颜色

R 覆盖几何多边形中的填充颜色,r,shiny,polygon,aesthetics,R,Shiny,Polygon,Aesthetics,我在R Shining应用程序中填充多边形图时遇到问题 我的代码: library(shiny) library(leaflet) library(DT) library(ggplot2) library(dplyr) r_colors <- rgb(t(col2rgb(colors()) / 255)) names(r_colors) <- colors() plotdata <- read.csv("RShinyCoral.csv") colnames(plotdata

我在R Shining应用程序中填充多边形图时遇到问题

我的代码:

library(shiny)
library(leaflet)
library(DT)
library(ggplot2)
library(dplyr)

r_colors <- rgb(t(col2rgb(colors()) / 255))
names(r_colors) <- colors()

plotdata <- read.csv("RShinyCoral.csv")
colnames(plotdata) <- c("Year1", "RLIMona", "Year2", "RLICatalina", "Year3", "RLILaParguera1998", "Year4", "RLILAPARGUERA2004")
parguera <- read.csv("RShinyCoral.csv")
parguera <- select(parguera, 5:8)
colnames(parguera) <- c("Year", "1998 Expedition", "Year", "2004 Expedition")
monaisland <- read.csv("RShinyCoral.csv")
monaisland <- select(monaisland, 1:2)
colnames(monaisland) <- c("Year", "Mona Island RLI")
islacatalina <- read.csv("RShinyCoral.csv")
islacatalina <- select(islacatalina, 3:4)
colnames(islacatalina) <- c("Year", "Isla Catalina RLI")



ui <- fluidPage(
  tags$a(href = "https://www.google.com/", "Click for Source Data"),
  titlePanel(tags$b("NOAA Puerto Rico Coral Luminescence (RLI, 5-year Running Average, 1730 - 1992)")),
  leafletOutput("mymap"),
  p(),
  fluidRow(
    column(3, actionButton("laparguera", "La Parguera Data"),
           actionButton("mona", "Mona Island Data"),
           actionButton("isla", "Isla Catalina Data")),

    column(9, 
           actionButton("visualize", "Add to Plot"),

           checkboxGroupInput("checkbox", label = NULL, 
                              c("La Parguera",  "Mona Island", "Isla Catalina"))
    )),
  fluidRow(column(12, DT::dataTableOutput('tbl')), 
  fluidRow(column(12,  plotOutput("plot1"))
  )
))
server <- function(input, output, session) {

  output$mymap <- renderLeaflet({
    leaflet() %>%
      addTiles() %>%
      addMarkers(lat = 17.95, lng = - 67.05, popup = "La Parguera ") %>%
      addMarkers(lat = 18.00, lng = -67.50, popup = "Mona Island") %>%
      addMarkers(lat = 18.2, lng = -69.00, popup = "Isla Catalina")
  })
  observeEvent(input$laparguera, {
    output$tbl <- DT::renderDataTable(DT::datatable(parguera, options = list(pagelength = 25)))
  })
  observeEvent(input$mona, {
    output$tbl <- DT::renderDataTable(DT::datatable(monaisland, options = list(pagelength = 25)))
  })
  observeEvent(input$isla, {
    output$tbl <- DT::renderDataTable(DT::datatable(islacatalina, options = list(pagelength = 25)))
  })


  output$plot1 <- renderPlot({
    if(length(input$visualize) == 0 ) return()
    isolate({
      if(length(input$checkbox) == 0) return()
      incheckbox <- input$checkbox
    }) # end isolate
    if(length(incheckbox) == 1) {
      switch(incheckbox,
             "Mona Island"= { gplot <- ggplot(data = plotdata) +
               geom_polygon(mapping = aes(x = Year1, y = RLIMona), na.rm = TRUE) +
               ylab("Candelas (5-year Running Average)" ) +
               guides(fill = FALSE)
             print(gplot) },
             "Isla Catalina"= { gplot6 <- ggplot(data = plotdata) +
               geom_polygon(mapping = aes(x = Year1, y = RLICatalina), na.rm = TRUE) +
               ylab("Candelas (5-year Running Average)" ) +
               xlim(1837, 1992) +
               guides(fill = FALSE)
             print(gplot6) },
             "La Parguera"= { gplot7 <- ggplot(data = plotdata) +
               geom_polygon(mapping = aes(x = Year1, y = RLILAPARGUERA2004), na.rm = TRUE) +
               ylab("Candelas (5-year Running Average)")  +
               xlim(1853,  1992)
             print(gplot7) }
      ) # end switch
    } else if(length(incheckbox) == 2) {
      if(all(c("La Parguera", "Mona Island") %in% incheckbox)) {
        gplot2 <- ggplot(data = plotdata) +
          geom_polygon(mapping = aes(x = Year1, y = RLIMona), na.rm = TRUE) +
          ylab("Candelas (5-year Running Average)" ) +
          xlim(1853,  1992) +
          geom_polygon(mapping = aes(x = Year1, y = RLILAPARGUERA2004), na.rm = TRUE) 
        print(gplot2)
      }  else if( all(c("Mona Island", "Isla Catalina") %in% incheckbox))  {
        gplot4 <- ggplot(data = plotdata) +
          geom_polygon(mapping = aes(x = Year1, y = RLIMona), na.rm = TRUE) +
          ylab("Candelas (5-year Running Average)" ) +
          geom_polygon(mapping = aes(x = Year1, y = RLICatalina), na.rm = TRUE) +
          xlim(1837, 1992)
        print(gplot4)
      } else if(all(c("La Parguera", "Isla Catalina") %in% incheckbox))    {
        gplot5 <- ggplot(data = plotdata) +
          geom_polygon(mapping = aes(x = Year1, y = RLICatalina), na.rm = TRUE) +
          ylab("Candelas (5-year Running Average)" ) +
          geom_polygon(mapping = aes(x = Year1, y = RLILAPARGUERA2004), na.rm = TRUE) +
          xlim(1853, 1992)
        print(gplot5)  
      }
    }  else if ( all(c("La Parguera", "Mona Island", "Isla Catalina") %in% incheckbox)) {
      gplot3 <- ggplot(data = plotdata) +
        geom_polygon(mapping = aes(x = Year1, y = RLIMona), na.rm = TRUE) +
        ylab("Candelas (5-year Running Average)" ) +
        geom_polygon(mapping = aes(x = Year1, y = RLILAPARGUERA2004), na.rm = TRUE) +
        geom_polygon(mapping = aes(x = Year1, y = RLICatalina), na.rm = TRUE) +
        xlim(1853, 1992)
      print(gplot3)
    } 

  })


}

shinyApp(ui, server)
库(闪亮)
图书馆(单张)
图书馆(DT)
图书馆(GG2)
图书馆(dplyr)

r_colors不确定为什么填充不起作用(例如,
ggplot(data=plotdata)+geom_polygon(mapping=aes(x=Year1,y=RLIMona),fill=“blue”,na.rm=TRUE)
),你也可以对其他岛屿的Hanks timfaber进行填充-我刚刚意识到我把填充放在了美学中,这是错误的。