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