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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:19:28+00:00 2026-05-31T13:19:28+00:00

I am using the following ggplot2 v0.9 scale_x_continious logic in a loop (by county

  • 0

I am using the following ggplot2 v0.9 scale_x_continious logic in a loop (by county name) in an attempt to plot each county’s data on a seperate plot with identical x scales.

MaxDays=365*3;
p <- p + scale_x_continuous(limits=c(0,MaxDays))
p <- p + scale_x_continuous(breaks=seq(0,MaxDays,60))

The logic works great, if all counties have data >= MaxDate. However, if the number of days is less than the MaxDate the charts x scales are not uniform (i.e say 0 – 720 days)

How can set the scalse to be absolute instead of a limit?

Any assistance woudl be greatly appreciated

############################################
###  Sample Data Below
############################################

# County 1 data
Days=seq(1,30,1)
Qty=Days*10
County=rep("Washington",length(Days))
df1=data.frame(County, Qty, Days)

# County 2 data
Days=seq(1,15,1)
Qty=Days*20
County=rep("Jefferson",length(Days))
df2=data.frame(County, Qty, Days)

# County 1 and 2 data
df3=rbind(df1,df2)

# calculate ranges for x scales
yrng=range(df3$Qty)
xrng=range(df3$Days)

# Scatter Plots
fname=paste("C:/test",".pdf",sep="");
pdf(fname,10,8,onefile=TRUE,paper="a4r");

p <- ggplot()
cnty=unique(df3$County)
n=length(unique(df3$County))
for (i in 1:n){
  df4<-subset(df3, County==cnty[i])
  p <- ggplot(df4, aes(x=Days, y=Qty))
  p <- p + geom_point()
  p <- p + opts(title=cnty[i])
  p <- p + scale_x_continuous(limits=c(xrng[1],xrng[2])) 
  p <- p + scale_x_continuous(breaks=seq(xrng[1],xrng[2],1))
  p <- p + coord_cartesian(xlim=c(xrng[1],xrng[2]))
print(p);
}
dev.off()
  • 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-31T13:19:28+00:00Added an answer on May 31, 2026 at 1:19 pm
    p <- p + coord_cartesian(xlim=c(0, MaxDays))
    

    EDIT: based on comments.

    Your problem is that the second scale_x_continuous() is replacing, not augmenting, the first, so the limits are not kept.

    You can replace the lines

    p <- p + scale_x_continuous(limits=c(xrng[1],xrng[2])) 
    p <- p + scale_x_continuous(breaks=seq(xrng[1],xrng[2],1))
    

    with

    p <- p + scale_x_continuous(limits=c(xrng[1],xrng[2]), 
                                breaks=seq(xrng[1],xrng[2],1))
    

    which gives something like this:

    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'm trying to plot heatmap in ggplot2 using csv data following casbon's solution in
I have a following plot with logarithmic y-scale that I plotted using ggplot2 in
I have the following graph that I generated using ggplot2 I had finalPlot as
From the documentation for ggplot2's geom_tile() function, we have the following simple plot: #
I am plotting a dataset using the following: plot = ggplot(transData, aes(x=Time, y=Value)) +
I have the following function, which I would like to plot using ggplot: f(x)
As question, I am trying to create a plot using the following code: chart.demo.sex.age
Using following console application i am converting each string to uppercase letters. But string
I produced multiple plots using the following code: set.seed(12345) a <- data.frame(Glabel=LETTERS[1:7], A=rnorm(7, mean
I have generated the following plot using the R code that follows it: ggplot(lengths,

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.