我知道我不是第一个在这个领域提出问题的人,但我无法找到解决我特殊困境的办法.这是我的问题的精简示例.
data<-data.frame(Est=c(1:20,1:20),Measured=c(1:5,5:9,1:6,3:6,1:6,3:6,1:4,4,4:8),variable=c(rep("Plot1",20),rep("Plot2",20)))
p<-ggplot(data,aes(y=Est,x=Measured,shape=variable))
p<- p + geom_point(stat="identity") +coord_fixed(xlim=c(0,25),ylim=c(0,25)) + theme_bw()
p #If you plot the figure at this point, the points stand alone in the legend
p<-p+ geom_abline(intercept=0,slope=1,aes(linetype="1:1",color="1:1"),show_guide=TRUE)
p # Once the geom_abline is added, there are lines through the points. :(
p<-p+scale_color_manual(name="Lines",
values=c("1:1"="black"))
p<- p + scale_linetype_manual(name="Lines",
values=c("1:1"=2))
p<-p + scale_shape_manual(values=c(0,20), name = "")
p<- p+xlab(expression(paste("Measured volume(",ducks^{3},"",ha^{-1},")",sep="")))
p<-p+ ylab(expression(paste("Estimated volume (",ducks^{3},"",ha^{-1},")",sep="")))
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,这些点的图例包括斜线(我认为它实际上是一条直线),我真的更喜欢这些点是独一无二的.
虽然示例代码只有1行和linetype,但我所做的实际数字包括五种不同颜色和线型的不同行,因此我需要一个解决方案,允许我包含多个指定颜色和线型的geom_abline调用.
不,我不是真正测量鸭子中任何东西的体积,尽管这对学习来说真的很有趣......
覆盖审美映射:
p + guides(shape = guide_legend(override.aes = list(linetype = 0)))
Run Code Online (Sandbox Code Playgroud)
我总是试图通过设置它来覆盖美学NULL
,但由于某种原因,直觉通常是错误的.
归档时间: |
|
查看次数: |
426 次 |
最近记录: |