Note that there are some explanatory texts on larger screens.

plurals
  1. POggplot2 scale_x_continuous limits or absolute
    primarykey
    data
    text
    <p>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.</p> <pre><code>MaxDays=365*3; p &lt;- p + scale_x_continuous(limits=c(0,MaxDays)) p &lt;- p + scale_x_continuous(breaks=seq(0,MaxDays,60)) </code></pre> <p>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)</p> <p>How can set the scalse to be absolute instead of a limit?</p> <p>Any assistance woudl be greatly appreciated</p> <pre><code>############################################ ### 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 &lt;- ggplot() cnty=unique(df3$County) n=length(unique(df3$County)) for (i in 1:n){ df4&lt;-subset(df3, County==cnty[i]) p &lt;- ggplot(df4, aes(x=Days, y=Qty)) p &lt;- p + geom_point() p &lt;- p + opts(title=cnty[i]) p &lt;- p + scale_x_continuous(limits=c(xrng[1],xrng[2])) p &lt;- p + scale_x_continuous(breaks=seq(xrng[1],xrng[2],1)) p &lt;- p + coord_cartesian(xlim=c(xrng[1],xrng[2])) print(p); } dev.off() </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload