-1

我已经为 R 中的住房成本和住房收入比率变量设置了时间序列折线图,但我没有成功地为每个变量指定不同的点符号,如其他帖子中所建议的那样。我收到以下错误消息“连续变量无法映射到形状”(简化为两个变量):

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())

欢迎提出任何建议。

4

1 回答 1

1

你非常接近:

## 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())

在此处输入图像描述

于 2013-10-10T23:32:16.750 回答