-1

I've set up a time series line graph for variables of ratios of housing cost and housing income in R but I'm having no success specifying different point symbols for each variable as suggested in other posts. I'm getting the error message “A continuous variable can not be mapped to shape” against the following (simplified for two variables):

ggplot(housing, aes(year)) + 
  geom_line(aes(y = Greenwich, colour = "Greenwich"))+
  geom_point(aes(y = Greenwich, colour = "Greenwich", shape = 1)) + 
  scale_shape_identity() + #added missing "+"
  geom_line(aes(y = median, colour = "median"))+
  geom_point(aes(y = median, colour = "median", shape = 2)) +  # added missing parenthesis
  scale_shape_identity() + # removed extra parenthesis 
  ylab("house price to earnings (lower quartile)")+ 
  theme(legend.title=element_blank())

Any suggestions most welcome.

Henrik
  • 65,555
  • 14
  • 143
  • 159
Curious56
  • 51
  • 1
  • 3
  • Hi and welcome to SO! First suggestion: please provide a [minimal, reproducible data set](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610) together with the code you have tried. Then you are much more likely to receive a rapid, helpful answer. Thanks! – Henrik Oct 10 '13 at 21:46
  • 1
    In trying to reformat so it would be clearer I found what appeared to be a missing "+"-sign. You might try with the new code. The error message suggests you may want to coerce a numeric variable to integer with `as.integer` or `trunc`. – IRTFM Oct 10 '13 at 21:58
  • @Henrik and DWin, I didn't realize you guys had seemingly edited the OP with a working example by the time I put up my answer. Sorry. – ako Oct 11 '13 at 00:02
  • Although you can get by with just one `scale_shape_identity()` call, and without getting the warning `Scale for 'shape' is already present`. Any reason to keep them both? – ako Oct 11 '13 at 00:28

1 Answers1

1

You are pretty close:

## toy data
year <- runif(20,10,20)
Greenwich <- runif(20,30,50)
median <- runif(20,30,50)
data<-data.frame(year,Greenwich,median)

## map it 
ggplot(data, aes(year)) +
  geom_line(aes(y = Greenwich, colour = "Greenwich"))+  scale_shape_identity()+
  geom_point(aes(y = Greenwich, colour = "Greenwich",shape = 12,size=8))+
  geom_line(aes(y = median, colour = "median")) +
  geom_point(aes(y = median, colour = "median",shape = 10,size=8))+ 
ylab("house price to earnings (lower quartile)")+
theme(legend.title=element_blank())

enter image description here

ako
  • 3,569
  • 4
  • 27
  • 38
  • Thank you so much DWin, Henrik and ako. Your amendments did the trick. This is the simplified data set I'm using: year Greenwich median 1 1997 3.38 3.82 2 1998 3.72 3.91 3 1999 4.13 4.11 4 2000 5.00 4.53 5 2001 5.59 4.97 6 2002 6.54 5.53 7 2003 7.73 6.59 8 2004 8.19 7.66 9 2005 8.09 8.08 10 2006 8.59 8.15 11 2007 8.59 8.59 12 2008 9.30 8.34 13 2009 8.27 7.30 14 2010 8.27 7.77 15 2011 8.80 7.53 16 2012 8.65 7.60 – Curious56 Oct 11 '13 at 18:11
  • @Curious56, if the answer addressed properly your question, you might consider accepting it by clicking on the green checkmark under the vote arrows. See more info on this [here](http://stackoverflow.com/help/someone-answers). Tks. – Andre Silva Jun 20 '14 at 21:44