How to plot a graph with more than 500 labels in the x axis?

I have a dataset with more than 500 labels and using a ggplot and ggplotly to plot a graph into a Shiny App.

The problem is that I can show only top 5 results from my dataset.

Is there any way to create a scroll, for example?

first of all: You should really think again if this make sense or isn't be presented better in another way.

Then, for ggplot (in combination with plotOutput) you can define the output size:

library(shiny)
library(tidyverse)

# generate some fake-data 
set.seed(1234)
df = tibble(
    value = runif(500, -5, 5)) %>% 
    rowwise() %>% 
    # I'm sure this can be done easier?
    mutate(name = str_c(sample(LETTERS,runif(1, 2,12), replace = TRUE), collapse = "")) %>% 
    arrange(desc(value)) %>% 
    distinct(name, .keep_all = TRUE) # we may have added some identical names by chance...


# Define UI for application that draws a histogram
ui <- fluidPage(

    # Application title
    titlePanel("Big Plot Example"),

    sidebarLayout(
        sidebarPanel(),
        

        # Show a plot of the generated distribution
        mainPanel(
           plotOutput("bigPlot")
        )
    )
)

# Define server logic required to draw a histogram
server <- function(input, output) {

output$bigPlot <- renderPlot({
    # make the plot 
    ggplot(df, aes(x = fct_reorder(name, value), y = value)) + 
        geom_col(fill = "lightsteelblue", 
                 width = 0.5) +
        coord_flip() +
        theme_minimal(base_size = 8)
    },
    width = 300,        # define the dimensions of the plot
    height = 3000)
}

# Run the application 
shinyApp(ui = ui, server = server)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.