gpt4 book ai didi

r - 添加 geom_smooth 时如何为图例中的点获得正确的形状和颜色?

转载 作者:行者123 更新时间:2023-12-04 09:32:31 27 4
gpt4 key购买 nike

如果我添加 geom_smooth,那么我会在 shape 图例中得到不同颜色的矩形,而不是黑色圆圈。我怎样才能防止这种情况发生?这是 sample code .

library(ggplot2)
df <- data.frame(x=rnorm(100), y=rnorm(100), z=runif(100))
qplot(x, y, size=z, data=df) +
geom_smooth(method='loess', aes(weight=z))

Incorrect point shape and color in legend

最佳答案

这是通过指定 size 美学特定于点层来解决的:

ggplot(df, aes(x = x, y = y)) +
geom_point(aes(size = z)) +
geom_smooth(method = "loess", aes(weight = z))

关于r - 添加 geom_smooth 时如何为图例中的点获得正确的形状和颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29955909/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com