我想画一个六边形图,如下图,旋转6个三元图形成六边形。有人能帮我吗?是否可以使用 plotly.express 或 ggtern 库?
library(shiny)
library(colourpicker)
library(ggplot2)
library(ggtern)
ui <- fluidPage(
titlePanel("TernaryPlot"),
fileInput("csv_file", "source", multiple = FALSE, accept = "csv",
width = NULL, buttonLabel = "Browse...",
placeholder = "No file selected"),
selectInput("x_val", "Choose x values:", choices=c()),
selectInput("y_val", "Choose y values:", choices=c()),
selectInput("z_val", "Choose z values:", choices=c()),
selectInput("a_val", "Choose a values:", choices=c()),
selectInput("b_val", "Choose b values:", choices=c()),
selectInput("c_val", "Choose c values:", choices=c()),
selectInput("d_val", "Choose d values:", choices=c()),
checkboxInput("show_point", "points", value = FALSE, width = NULL),
checkboxInput("show_dens", "density", value = FALSE, width = NULL),
plotOutput("ggtern")
)
server <- function(session,input, output) {
selectedData <- reactive({
inFile <- input$csv_file
if (is.null(inFile))
return(NULL)
df <- read.csv(inFile$datapath,na.strings = c("", "NA", "#N/A"))
updateSelectInput(session,"x_val","x series",colnames(df))
updateSelectInput(session,"y_val","y series",colnames(df))
updateSelectInput(session,"z_val","z series",colnames(df))
updateSelectInput(session,"a_val","a series",colnames(df))
updateSelectInput(session,"b_val","b series",colnames(df))
updateSelectInput(session,"c_val","c series",colnames(df))
updateSelectInput(session,"d_val","d series",colnames(df))
return(df)
})
output$ggtern <- renderPlot({
if (is.null(selectedData()))
return(NULL)
req(input$x_val)
req(input$y_val)
req(input$z_val)
req(input$a_val)
req(input$b_val)
req(input$c_val)
req(input$d_val)
obj1 <- ggtern(data=selectedData(), aes_string(x = input$x_val, y = input$y_val, z = input$z_val)) + geom_point()
obj2 <- ggtern(data=selectedData(), aes_string(x = input$z_val, y = input$y_val, z = input$a_val)) + geom_point() + theme_rotate(degrees = 45 )
obj3 <- ggtern(data=selectedData(), aes_string(x = input$a_val, y = input$y_val, z = input$b_val)) + geom_point() + theme_rotate(degrees = 130 )
obj4 <- ggtern(data=selectedData(), aes_string(x = input$b_val, y = input$y_val, z = input$c_val)) + geom_point() + theme_rotate(degrees = 180 )
obj5 <- ggtern(data=selectedData(), aes_string(x = input$c_val, y = input$y_val, z = input$d_val)) + geom_point() + theme_rotate(degrees = 230 )
obj6 <- ggtern(data=selectedData(), aes_string(x = input$d_val, y = input$y_val, z = input$x_val)) + geom_point() + theme_rotate(degrees = 300 )
print(obj1)
print(obj2)
print(obj3)
print(obj4)
print(obj5)
print(obj6)
})
}
shinyApp(ui = ui, server = server)