Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4080444
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:55:52+00:00 2026-05-20T17:55:52+00:00

ggplot generally does a good job of creating sensible breaks and labels in scales.

  • 0

ggplot generally does a good job of creating sensible breaks and labels in scales.

However, I find that in plot with many facets and perhaps a formatter= statement, the labels tend to get too “dense” and overprint, for example in this picture:

df <- data.frame(
        fac=rep(LETTERS[1:10], 100),
        x=rnorm(1000)
)

ggplot(df, aes(x=x)) + 
  geom_bar(binwidth=0.5) + 
  facet_grid(~fac) + 
  scale_x_continuous(formatter="percent")

enter image description here

I know that I can specify the breaks and labels of scales explicitly, by providing breaks= and scale= arguments to scale_x_continuous.

However, I am processing survey data with many questions and a dozen crossbreaks, so need to find a way to do this automatically.

Is there a way of telling ggplot to calculate breaks and labels automatically, but just have fewer, say at the minimum, maximum and zero point?

EDIT: Ideally, I don’t want to specify the minimum and maximum points, but somehow tap into the built-in ggplot training of scales, and use the default calculated scale limits.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T17:55:53+00:00Added an answer on May 20, 2026 at 5:55 pm

    You can pass in arguments such as min() and max() in your call to ggplot to dynamically specify the breaks. It sounds like you are going to be applying this across a wide variety of data so you may want to consider generalizing this into a function and messing with the formatting, but this approach should work:

    ggplot(df, aes(x=x)) + 
      geom_bar(binwidth=0.5) + 
      facet_grid(~fac) + 
      scale_x_continuous(breaks = c(min(df$x), 0, max(df$x))
        , labels = c(paste( 100 * round(min(df$x),2), "%", sep = ""), paste(0, "%", sep = ""), paste( 100 * round(max(df$x),2), "%", sep = ""))
        )
    

    or rotate the x-axis text with opts(axis.text.x = theme_text(angle = 90, hjust = 0)) to produce something like:

    enter image description here

    Update

    In the latest version of ggplot2 the breaks and labels arguments to scale_x_continuous accept functions, so one can do something like the following:

    myBreaks <- function(x){
        breaks <- c(min(x),median(x),max(x))
        names(breaks) <- attr(breaks,"labels")
        breaks
    }
    
    ggplot(df, aes(x=x)) + 
      geom_bar(binwidth=0.5) + 
      facet_grid(~fac) + 
      scale_x_continuous(breaks = myBreaks,labels = percent_format()) + 
      opts(axis.text.x = theme_text(angle = 90, hjust = 1,size = 5))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to make a plot with ggplot that looks very close to
I'm trying to write a function that plots a ggplot facet_wrap plot over multiple
I want to plot data from different data frames with ggplot. However, I'm having
I love the plots that ggplot generates. However, it is still somewhat cumbersome to
I have generated the following plot using the R code that follows it: ggplot(lengths,
ggplot(int_times,aes(x=-stim ,y=num,colour=gene)) + scale_y_continuous(breaks=int_times$num,labels=int_times$gene) + geom_segment(aes(xend=stim,ystart=num,yend=num),size=5) + xlab('IW (min)') + ylab('Genes') + opts(title='multi') int_times:
When overlaying ggplot density plots that feature data of same length but different scales
I've been learning ggplot in the last few weeks. Generally, I'm getting things done
Here's a plot: library(ggplot2) ggplot(mtcars, aes(x = factor(cyl), y = hp, group = factor(am),
I have a a stacked bar plot using ggplot for which I'm trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.