我已经为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())
欢迎提出任何建议。
答案 0 :(得分: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())