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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:35:57+00:00 2026-06-17T02:35:57+00:00

I have a data frame where some variables present little relative variation and some

  • 0

I have a data frame where some variables present little relative variation and some others present a high variation. For instance, consider the following data frame:

df <- data.frame(IDX = 1:10, V1 = runif(10) + 100000, V2 = runif(10))

with the following contents:

   IDX       V1         V2
1    1 100001.0 0.39601382
2    2 100000.1 0.76472032
3    3 100000.1 0.10183021
4    4 100000.2 0.12735142
5    5 100000.8 0.21488898
6    6 100000.1 0.92675265
7    7 100000.5 0.27987290
8    8 100000.6 0.69132304
9    9 100000.5 0.20719782
10  10 100000.8 0.02314787

The absolute variation for both variables is similar (0.10 for V1 and 0.09 for V2). But, if we consider the relative variation with respect to their means, then the variation for V1 is very little while the opposite occurs for V2:

> var(df$V1) / mean(df$V1)
[1] 1.082472e-06
> var(df$V2) / mean(df$V2)
[1] 0.2617366

The problem comes when I try to make a dotplot for both variables, and I try to set the limits for the X scale. If I use the same scale for each variable (relation = 'same', the default setting), I obtain the following:

plot1

Here you have the code used to create the plot:

library(lattice)
library(reshape2)
df <- melt(df, id.vars = 'IDX')

# approach 1
pl <- dotplot(IDX ~ value | variable, df,
              scales = list(x = list(relation = 'same')))
print(pl)

As you can see V2’s values are so small, that when using the same scale for both panels it seems as if there were no variation among V2 values. If I make the X scale for each panel independent, then I get the following:

plot2

And here you have the code to produce the second plot:

# approach 2
pl <- dotplot(IDX ~ value | variable, df,
              scales = list(x = list(relation = 'free')))
print(pl)

The problem now is that the range of the X scale for the left panel goes from 100000.2 to 100001.0, and the data looks as if there was a lot of variation, when in reality it is not like that.

Somehow, I would like to obtain a plot where the left panel looked like the left panel in the first plot, and the right panel looked like the right panel in the second plot. My idea was to define the X ranges based on the mean of the variable being plotted. For instance, for each panel, the X limits could go from 0.9 * mean to 1.1 * mean. But I do not know how to do that in the presence of multiple variables (and panels).

  • 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-17T02:36:00+00:00Added an answer on June 17, 2026 at 2:36 am

    The cleanest solution will probably be to supply your own prepanel function, which will set each panel’s x-limits ‘on the fly’. Here is an example that sets xlim to extend from 0 to the maximum value of x present in a panel

    dotplot(IDX ~ value | variable, df, scales=list(relation="free"),
            prepanel = function(x,y,...) list(xlim=c(0, max(x))))
    

    enter image description here

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

Sidebar

Related Questions

I have data frame with some numerical variables and some categorical factor variables. The
I have the the following data frame and variables: u0 <- c(1,1,1,1,1) df <-
I have a data frame with a grouping variable 'ID' and some values ('Value'):
I have a data frame where some of the columns contain NA values. How
I have a data frame that is some 35,000 rows, by 7 columns. it
I have a large data.frame displaying some weird properties when plotted. I'd like to
I have a data frame with an id column and some (potentially many) columns
I have a data frame in R that has come about from running some
I have some data in a dataframe calvarbyruno.1 with variables Nominal and PAR that
I have a large data frame with date variables, which reflect first day of

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.