ggplot2:更改图例中的符号

Tim*_*Tim 3 r legend ggplot2

我有一个问题,使我的情节图例中的符号与情节本身中的符号相匹配.

假设数据有四列,如下所示

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))
)
Run Code Online (Sandbox Code Playgroud)

我希望点数是不同的大小(由'Rank'区分)并用不同的符号表示(十字和空心圆,由'Quantified'区分).

我的代码是

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)
 )
Run Code Online (Sandbox Code Playgroud)

图中的符号是我想要的.

我的问题是,我希望顶部图例中的圆圈没有填充,因为它们在情节中.

我已经在代码的不同部分尝试了各种命令(例如,fill ="white"),但似乎没有什么工作正常.

有什么建议?

jor*_*ran 9

现在我确定这是你想要的:

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)))
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述