【发布时间】:2016-08-12 17:14:42
【问题描述】:
我正在尝试制作三个线图的侧面图,并且在每个线图中都有三条线。我想让与“oirf”相对应的线为实线,而与“upperCI”和“lowerCI”相对应的两条线都是虚线,无论是相同类型的虚线还是看起来非常相似的东西,就像这样:
但是我遇到了一个我无法解决的错误。
这是我的数据:
"countrySpellId","iso","country","step","indicator","vals"
38,"BLR","Belarus",0,"oirf",-0.19979745478058
38,"BLR","Belarus",1,"oirf",-0.182586795026907
38,"BLR","Belarus",2,"oirf",-0.242312010909111
106,"GEO","Georgia",0,"oirf",-0.154580915298088
106,"GEO","Georgia",1,"oirf",-0.0572862343086547
106,"GEO","Georgia",2,"oirf",-0.345457860190889
167,"KGZ","Kyrgyzstan",0,"oirf",0.960777168532119
167,"KGZ","Kyrgyzstan",1,"oirf",0.458003383067036
167,"KGZ","Kyrgyzstan",2,"oirf",0.190725669245905
38,"BLR","Belarus",0,"lowerCI",-0.357909781851253
38,"BLR","Belarus",1,"lowerCI",-0.411483619567094
38,"BLR","Belarus",2,"lowerCI",-0.514508124910321
106,"GEO","Georgia",0,"lowerCI",-0.323219475085121
106,"GEO","Georgia",1,"lowerCI",-0.236286319570866
106,"GEO","Georgia",2,"lowerCI",-0.540228716700013
167,"KGZ","Kyrgyzstan",0,"lowerCI",0.448913075973564
167,"KGZ","Kyrgyzstan",1,"lowerCI",0.0581860926615476
167,"KGZ","Kyrgyzstan",2,"lowerCI",-0.235580302805703
38,"BLR","Belarus",0,"upperCI",-0.0416851277099078
38,"BLR","Belarus",1,"upperCI",0.0463100295132811
38,"BLR","Belarus",2,"upperCI",0.0298841030920997
106,"GEO","Georgia",0,"upperCI",0.0140576444889454
106,"GEO","Georgia",1,"upperCI",0.121713850953557
106,"GEO","Georgia",2,"upperCI",-0.150687003681766
167,"KGZ","Kyrgyzstan",0,"upperCI",1.47264126109067
167,"KGZ","Kyrgyzstan",1,"upperCI",0.857820673472524
167,"KGZ","Kyrgyzstan",2,"upperCI",0.617031641297513
这就是我试图做的情节:
ggplot(data = oirfsFacetPlot2, aes(x = step, y = vals, group = countrySpellId,
stat = "identity")) +
geom_line(aes(linetype = indicator)) +
xlab("Month") + ylab("Percent change") +
theme_bw() + scale_x_continuous(breaks = seq(0,3,1)) +
scale_linetype_discrete(name ="indicator",
breaks=c("lowerCI", "oirf","upperCI")) +
facet_wrap( ~ country, scales = "free_y", nrow = 3 )
但后来我得到了这个错误,我认为这与aes(linetype = indicator)有关。
错误:geom_path:如果您使用的是虚线或虚线,则颜色、大小和线型必须在整个线上保持不变
我做错了什么?
【问题讨论】:
-
图片未显示
-
从您的
aes中删除group(以及在您使用它时的stat)。