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 8273167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:23:13+00:00 2026-06-08T07:23:13+00:00

I have a dataframe capturing several measures over time that I would like to

  • 0

I have a dataframe capturing several measures over time that I would like to visualize a 3×1 facet. However, each measure contains different units/scales that would benefit from custom transformations and labeling schemes.

So, my question is: If the units and scales are different across different facets, how can I specify a custom formatter or transformation (i.e., log10) to a particular axis within a facet?

For example, let’s say I have the data:

df = data.frame(dollars=10^rlnorm(50,0,1), counts=rpois(50, 100))
melted.df = melt(df, measure.var=c("dollars", "counts"))

How would one go upon setting up a 2×1 facet showing dollars and counts over the index with labels=dollars and scale_y_continuous(trans = "log10", ...) for the df$dollars data?

Thank you!

  • 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-06-08T07:23:16+00:00Added an answer on June 8, 2026 at 7:23 am

    As you discovered, there isn’t an easy solution to this, but it comes up a lot. Since this sort of thing is asked so often, I find it helpful to explain why this is hard, and suggest a potential solution.

    My experience has been that people coming to ggplot2 or lattice graphics fundamentally misunderstand the purpose of faceting (or trellising, in lattice). This feature was developed with a very specific idea in mind: the visualization of data across multiple groups that share a common scale. It comes from something called the principle of small multiples, espoused by Tufte and others.

    Placing panels next to each other with very different scales is something that visual design experts will tend to avoid, because it can be at best misleading. (I’m not scolding you here, just explaining the rationale…)

    But of course, once you have this great tool out in the open, you never know how folks are going to use it. So it gets stretched: the requests come in for the ability to allows the scales to vary by panel, and to set various aspects of the plot separately for each panel. And so faceting in ggplot2 has been expanded well beyond its original intent.

    One consequence of this is that some things are difficult to implement simply due to the original design intent of the feature. This is likely one such instance.

    Ok, enough explanation. Here’s my solution.

    The trick here is to recognize that you aren’t plotting graphs that share a scale. To me, that means you shouldn’t even be thinking of using faceting at all. Instead, make each plot separately, and arrange them together in one plot:

    library(gridExtra)
    
    p1 <- ggplot(subset(melted.df,variable == 'dollars'),
                    aes(x = value)) + 
                facet_wrap(~variable) + 
                geom_density() + 
                scale_x_log10(labels = dollar_format())
    
    p2 <- ggplot(subset(melted.df,variable == 'counts'),
                    aes(x = value)) + 
                facet_wrap(~variable) + 
                geom_density()
    
    grid.arrange(p1,p2)
    

    enter image description here

    I’ve just guessed at what geom_* you wanted to use, and I’m sure this isn’t really what you wanted to plot, but at least it illustrates the principle.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a dataframe with a column of integers that I would like to
I have a dataframe and would like to add a new column where the
I have a dataframe called data where I would like to rescale the values
I have a big dataframe with columns such as: ID, time, OS, IP Each
I'd like to melt the dataframe so that in one column I have dates
I have a dataframe that looks like this DF: V1 V2 V3 V4 V5
I would like to transform/modify the content of dataframe. Basically I have a dataframe
I have dataframe that contains 70-80 rows of ordered response time (rt) data for
I have a dataframe that looks like this: data median min max no_of_threads 2.33
I have a dataframe and would like to calculate the correlation (with Spearman, data

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.