ggplot2:更改图例中的符号 [英] ggplot2: Making changes to symbols in the legend
问题描述
我遇到了一个问题,使得我的情节图例中的符号与情节本身中的符号相匹配。
假设数据有四列这样的数据
data = data .frame(x = sample(1:10,10,replace = TRUE),y = sample(1:10,10,replace = TRUE),
Rank = sample(1:10,10,replace = TRUE ),量化=因子(样本(1:2,10,替换= TRUE))
)
我希望积分是不同的尺寸(以'Rank'来区分),并用不同的符号(十字和空心圆,以'量化'来区分)代表。
我的代码是
ggplot(data,aes(x = x,y = y))+
geom_point(aes(size = Rank,shape = Quantified))+
scale_shape_manual(Quantified,labels = c(Yes,No = c(1,4)
)
图中的符号是我想要的他们。
我的问题是,我希望顶部图例中的圆圈像
我已经在代码的不同部分尝试了各种命令(例如fill =white),但没有任何东西可以正常工作。
有什么建议吗?
现在我确定它就是您想要的:
<$ (尺寸)
ggplot(数据,aes(x = x,y = y))+
geom_point(aes(size = Rank,shape = Quantified) )+
scale_shape_manual(Quantified,labels = c(Yes,No),values = c(1,4))+
guides(size = guide_legend(override.aes = list (shape = 1)))
I'm having a problem making the symbols in the legend of my plot match those in the plot itself.
Suppose the data has four columns like this
data = data.frame(x = sample(1:10, 10, replace=TRUE), y = sample(1:10, 10, replace=TRUE),
Rank = sample(1:10, 10, replace = TRUE), Quantified = factor(sample(1:2, 10, replace = TRUE))
)
I would like points to be different sizes (distinguished by 'Rank') and represented by different symbols (crosses and open circles, distinguished by 'Quantified').
My code is
ggplot(data, aes(x = x, y = y)) +
geom_point(aes(size = Rank, shape = Quantified)) +
scale_shape_manual("Quantified", labels = c("Yes", "No"), values = c(1, 4)
)
The symbols in the plot are as I want them.
My problem is that I would like the circles in the top legend to be unfilled as they are in the plot.
I've tried a variety of commands in different parts of the code (e.g., fill = "white") but nothing seems to work quite right.
Any suggestions?
Now that I'm sure it's what you want:
library(scales)
ggplot(data, aes(x = x, y = y)) +
geom_point(aes(size = Rank, shape = Quantified)) +
scale_shape_manual("Quantified", labels = c("Yes", "No"), values = c(1, 4)) +
guides(size = guide_legend(override.aes = list(shape = 1)))
这篇关于ggplot2:更改图例中的符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!