I'm trying to provide individual titles for each of my graphs within plotly
's subplot
function and I found a post where you can extend subplot using %>% layout(title = "Main Title)
but I'd like individual titles for each graph (I'm using ggtitle
but that only plots the last title provided (Plot 4). I found a similar post Provide title to each of the subplots - R Shiny but I don't think that I can facet_wrap
in my scenario.
Furthermore - I was wondering how to increase the margin between the graphs in a subplot since they seemed to be really squished together.
Any help appreciated!
ui <- fluidPage(
sidebarPanel("This is a sidebar"),
mainPanel(plotlyOutput("myplot"))
)
server <- function(input, output){
output$myplot <- renderPlotly({
gg1 <- ggplotly(
ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width)) +
geom_point() +
theme_minimal() +
ggtitle("Plot 1")
)
gg2 <- ggplotly(
ggplot(iris, aes(x=Species, y=Sepal.Length)) +
geom_boxplot() +
theme_minimal() +
ggtitle("Plot 2")
)
gg3 <- ggplotly(
ggplot(iris, aes(x=Petal.Width)) +
geom_histogram() +
ggtitle("Plot 3")
)
gg4 <- ggplotly(
ggplot(iris, aes(x=Petal.Length)) +
geom_histogram() +
ggtitle("Plot 4")
)
subplot(list(gg1,gg2,gg3,gg4), nrows = 2)
})
}
shinyApp(ui = ui, server = server)