土壤纹理三角形不会绘制

问题描述 投票:0回答:1

我从美国农业部数据中绘制的土壤纹理三角形在闪亮的外部起作用,但在内部不起作用,我只是想让它在这里绘制“基础”。它甚至还没有反应。您对我收到错误的原因有什么建议吗:

警告:FUN 中的错误:参数的“类型”(字符)无效。

当我将代码从外部闪亮移动到内部闪亮时,似乎发生了错误。我已经确保我的包没有交互。

library(ggplot2)
library(dplyr)
library(shinythemes)
library(tidyverse)
library(shiny)
library(aqp)
library(soilDB)
library(RColorBrewer)
library(latticeExtra)
library(reshape2)
library(sjPlot)
library(bslib)
library(ggtern)
library(grid)


# Define the UI for the app
ui <- fluidPage(
  theme = shinythemes::shinytheme("flatly"),
  titlePanel("Soil"),
  
  # Create the tabset panel
  tabsetPanel(
    
    tabPanel("Soil", 
             h3("Soil  Figures"),
             column(6, 
                    card(plotOutput("plot3"),
                         textOutput("plot3_caption")
                         
                    )
             )
    )
  )
  
  
)

# Define the server logic
server <- function(input, output, session) {
  
  output$plot3 <- renderPlot({
    
    # Put tile labels at the midpoint of each tile using dplyr instead of plyr
    USDA.LAB <- USDA %>%
      dplyr::group_by(Label) %>%
      dplyr::summarise(
        Clay = mean(Clay),
        Sand = mean(Sand),
        Silt = mean(Silt)
      )
    
    # Tweak
    USDA.LAB$Angle = 0
    USDA.LAB$Angle[which(USDA.LAB$Label == 'Loamy Sand')] = -35
    
    # Custom 12 colors palette
    custom_colors <- c(
      "#E5C4A1", 
      "#D47D35", # (Warm Orange)
      "#C0C0C0", #(Light Gray)
      "#9F7F4E", #(Earthy Brown)
      "#6A7F67", #(Muted Green)
      "#E2D9A7", #(Pastel Yellow)
      "#9D62A0", #(Lavender Purple)
      "#B67E5D", #(Dusty Coral)
      "#A9D6A1",#(Mint Green)
      "#D1A6D8", #(Pastel Pink)
      "#D4B97B", #(Golden Yellow)
      "#3E6E58" #(Dark Green)
    )
    
    # Construct the plot
    base <-  ggplot(data = USDA, aes(y=Clay, x=Sand, z=Silt)) +
      coord_tern(L="x",T="y",R="z") +
      geom_polygon(alpha = 0.75, size = 0.5, color = 'black',
                   aes(color=Label, fill=Label)) +
      scale_fill_manual(values = custom_colors) +   # Custom colors for fill
      scale_color_manual(values = custom_colors) +  # Custom colors for borders
      geom_text(data = USDA.LAB,
                aes(label = Label, angle = Angle),
                color = 'black',
                size = 3.5) +
      theme_rgbw() +
      theme_showsecondary() +
      theme_showarrows() +
      custom_percent("Percent") +
      theme(legend.justification = c(0, 1),
            legend.position      = c(0, 1),
            axis.tern.padding    = unit(0.15, 'npc')) +
      labs(title = 'USDA Textural Classification Chart',
           fill  = 'Textural Class',
           color = 'Textural Class')
    
    
    base 
    
    
  })
  
  output$plot3_caption <- renderText({
    "The plot above shows..."
  })
  
  
  
  
  
  
}

# Run the application 
shinyApp(ui = ui, server = server)
r ggplot2 shiny soil ggtern
1个回答
0
投票

我无法完全解释原因,但是由于this问题引用了到这个,您需要通过将

print()
更改为
base
来明确地
print(base)
您的ggplot元素。 这似乎是一个简单的解决方法。这些问题都是旧问题(2016-2018),我不明白为什么现在会发生。

© www.soinside.com 2019 - 2024. All rights reserved.