gpt4 book ai didi

r - 如何获取geom_smooth()忽略我的颜色分组

转载 作者:行者123 更新时间:2023-12-04 00:56:03 25 4
gpt4 key购买 nike

我正在尝试为我的因子的两个水平(按颜色分组)用拟合线绘制图。我使用形状对另一个变体进行分组,但是当我尝试更平滑地拟合时,最终得到4条线,而我总共只需要两条线(每种颜色1条)

这是我使用的数据和代码:

data <- structure(list(K = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("2s", "4s"), class = "factor"),
q = c(0.12, 0.11, 0.1, 0.09, 0.08, 0.07, 0.06, 0.05, 0.04,
0.03, 0.02, 0.01, 0.12, 0.11, 0.1, 0.09, 0.08, 0.07, 0.06,
0.05, 0.04, 0.03, 0.02, 0.01, 0.12, 0.11, 0.1, 0.09, 0.08,
0.07, 0.06, 0.05, 0.04, 0.03, 0.02, 0.01, 0.12, 0.11, 0.1,
0.09, 0.08, 0.07, 0.06, 0.05, 0.04, 0.03, 0.02, 0.01), rarity = c(0.907,
0.9206, 0.9359, 0.9321, 0.9405, 0.9344, 0.9449, 0.9106, 0.8844,
0.8829, 0.8989, 0.798, 0.7464, 0.8225, 0.877, 0.8521, 0.9127,
0.9317, 0.9245, 0.9595, 0.9628, 0.9573, 0.9423, 0.9428, 0.5802,
0.6414, 0.5123, 0.57, 0.587, 0.5655, 0.5231, 0.517, 0.4694,
0.5459, 0.3745, 0.3274, 0.7936, 0.7821, 0.7297, 0.7227, 0.6814,
0.6608, 0.6721, 0.6202, 0.5924, 0.5659, 0.5448, 0.6138),
metric = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("APD", "ED"
), class = "factor")), .Names = c("K", "q", "rarity", "metric"
), class = "data.frame", row.names = c(NA, -48L))

library(ggplot2)
ggplot(data=data, aes(x=q, y=rarity, colour=metric, shape=K))+
ggtitle("Relationship")+
xlab("rate of character change")+
ylab("Correlation coefficient to average rarity")+
geom_point()+
geom_smooth(method=lm,se=FALSE)


有什么建议吗?

最佳答案

如果每个组都被metricK分开,则会得到两行。您确实希望shape美学仅应用于点图层,而不是稍后的平滑。最好只是将该属性的aes()移动到那里。

ggplot(data=data, aes(x=q, y=rarity, colour=metric))+ 
ggtitle("Relationship")+
xlab("rate of character change")+
ylab("Correlation coefficient to average rarity")+
geom_point(aes(shape=K))+
geom_smooth(method=lm,se=FALSE)


enter image description here

关于r - 如何获取geom_smooth()忽略我的颜色分组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33293606/

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