0

I need to get my X axis to intercept at 1950.

I have tried: scale_x_continuous(expand=c(0,0))with no luck, do I need to fix the x axis at 1950 instead of 0?

Current error: Error: Discrete value supplied to continuous scale

enter image description here

Here is the code used to create the plot!

Plot <- ggplot(d2,aes(x = date,
              y = y)) + 
  geom_area(data=subset(d2, y<=0), fill="blue") + 
  geom_area(data=subset(d2, y>=0), fill="red") + 
  scale_y_continuous(name = "MEI")+
  xlab("Year")+
  theme(axis.text.y   = element_text(size=24),
        axis.text.x   = element_text(size=24),
        axis.title.y  = element_text(size=24),
        axis.title.x  = element_text(size=24),
        panel.background = element_blank(),
        panel.grid.major = element_line(colour = "grey"), 
        strip.background = element_blank(),
        panel.border = element_rect(colour = "black", fill = NA),
        axis.line = element_line(colour = "black"))

Example Data below:

 x      y                date
1    -631152000 -1.018 1950-01-01 01:32:40
2    -628473600 -1.143 1950-02-01 01:32:40
3    -626054400 -1.290 1950-03-01 01:32:40
4    -623376000 -1.061 1950-04-01 01:32:40
5    -620784000 -1.416 1950-05-01 01:32:40
6    -618105600 -1.372 1950-06-01 01:32:40
7    -615513600 -1.334 1950-07-01 01:32:40
8    -612835200 -1.050 1950-08-01 01:32:40
9    -610156800 -0.578 1950-09-01 01:32:40
10   -607564800 -0.395 1950-10-01 01:32:40
Methexis
  • 2,739
  • 5
  • 24
  • 34
  • 2
    you need to do what? – rawr Oct 18 '14 at 14:39
  • 1
    Its not clear what your are trying to do, at least not for me and potentially, other folks here who might try answering your question. Could you clarify this statement: "I need to get my X axis to intercept at 1950.". Do yo mean that you want to remove the little space to the left of 1950 i.e. so that your *X axis intercepts your Y axis at x=1950?* – shekeine Oct 18 '14 at 14:48
  • 2
    Believe @Shekeine's speculation is correct. The error message is actually pretty clear: Current error: Error: Discrete value supplied to continuous scale. Suggest to provide sample data and the code. – KFB Oct 18 '14 at 14:53
  • 1
    A simple example definitely works as expected: `d <- data.frame(x=1:10,y=rnorm(10)); ggplot(d,aes(x,y))+ geom_line()+ scale_x_continuous(expand=c(0,0))` -- so as @KFB says we need to see a reproducible example http://tinyurl.com/reproducible-000 – Ben Bolker Oct 18 '14 at 15:11
  • Yep, I need to get rid of that little bit of space! – Methexis Oct 18 '14 at 19:03
  • Could it be due to the full date format? – Methexis Oct 18 '14 at 19:27
  • @Methexis; might be worth deleting this question now – user20650 Oct 19 '14 at 14:14

0 Answers0