ggplot图中线条的动态形状和大小更改创建第二个图例 [英] ggplot Dynamic Shape and Size change of lines on graph Creates Second Legend
本文介绍了ggplot图中线条的动态形状和大小更改创建第二个图例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想改变2行上的点的形状和大小,我可以做到这一点,但第二个图例出现。
运行此代码时,您会看到2个传说。我只想要变量图例。
library(ggplot2)
MyData< -data.frame(时间= c(1,2,3,1,2,3),值= c(.4,.6,.7,.1,.2,.3),变量= c(公司a,公司a,公司a,公司b,公司b,公司b))
MyData $ pointsize< - ifelse(MyData $ time == 2,5,1)
MyData $ shape< - ifelse(MyData $ time == 2,4,7)
MyData
ggplot(MyData,aes(x = time,y = value,color = variable,group =变量))+ geom_line()+ geom_point(aes(shape = MyData $ pointsize,size = MyData $ pointsize))+
scale_shape_identity()
如何删除Mydata $ PointSize的图例?
谢谢!
<您可以在
scale_size_continuous()$ c中设置 guide = FALSE
$ b + scale_size_continuous(guide = FALSE)
I want to change the shape and size of a points on 2 lines and I can do that but a second legend appears.
When you run this code you will see 2 legends. I only want the "variable" legend.
library("ggplot2")
MyData<-data.frame(time= c(1,2,3,1,2,3), value = c(.4,.6,.7,.1,.2,.3), variable = c("company a","company a","company a","company b","company b","company b") )
MyData$pointsize <- ifelse(MyData$time==2, 5, 1)
MyData$shape <- ifelse(MyData$time==2, 4, 7)
MyData
ggplot(MyData, aes( x = time, y=value,colour=variable, group= variable) ) + geom_line() + geom_point(aes(shape = MyData$pointsize,size = MyData$pointsize) )+
scale_shape_identity()
How do I remove the legend for Mydata$PointSize?
Thank you!
解决方案 You can set guide=FALSE
inside the scale_size_continuous()
to remove this legend.
+scale_size_continuous(guide=FALSE)
这篇关于ggplot图中线条的动态形状和大小更改创建第二个图例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文