【发布时间】:2022-01-11 06:48:26
【问题描述】:
我想为用户提供的任何数字变量创建凸包的 ggplot 视觉效果,同时允许将包拆分为所选分类输入变量的多个包。
类似这样的东西,用户可以根据需要选择任意数量的 x 变量
library(datasets)
library(ggplot2)
library(ggpubr)
df<- iris
str(df)
b <- ggplot(df, aes(x = Sepal.Length+Sepal.Width, y = Petal.Width))
# Convex hull of groups
b + geom_point(aes(color = Species, shape = Species)) +
stat_chull(aes(color = Species, fill = Species),
alpha = 0.1, geom = "polygon") +
scale_color_manual(values = c("#00AFBB", "#E7B800", "#FC4E07")) +
scale_fill_manual(values = c("#00AFBB", "#E7B800", "#FC4E07"))
到目前为止,这是我的闪亮代码,不用说它不起作用。任何帮助将不胜感激
library(shiny)
library(dplyr)
library(ggplot2)
library(ggpubr)
df<- mtcars
numeric_cols <- df %>% select(where(is.numeric))
categorical_cols <- df %>% select(where(is.factor))
ui <- fluidPage(
titlePanel("MTCARS"),
selectInput("Columns","Numeric Columns",
names(numeric_cols), multiple = TRUE),
selectInput("Columns","Categorical Columns",
names(categorical_cols), multiple = TRUE),
plotOutput("myplot")
)
server <- function(input, output) {
Dataframe2 <- reactive({
mtcars[,input$Columns]
})
my_plot<- reactive({ggplot(Dataframe2(), aes(mpg, cyl))+geom_point()})
output$myplot <- renderPlot({
my_plot()
})
}
shinyApp(ui, server)
【问题讨论】:
标签: r ggplot2 shiny convex-hull