关于 r:调整 geom_point 的颜色以反映样本均值的差异? | 珊瑚贝

Adjusting color of geom_point to reflect difference in sample means?


我正在尝试使用 R 中的 ggplot 可视化我的配对 t 检验。我想使用 ggplot geom_point() 将两个样本相互绘制,但我想调整点的颜色以显示差异的严重性样本手段。有了这个,我的意思是,如果该点在配对群体的平均值上的差异为 0,它将位于回归线上并且只是一个黑点。如果该点差异很大并且位于图形的左上象限或右下象限,远离回归线,我希望它是红色的。在梯度尺度上。我希望这是有道理的!我将附上我的图表的图片以显示:

graph

现在我唯一的审美是阿尔法,所以点更明显。

在这方面的任何帮助都会很棒!谢谢!


你没有给我们任何样本数据,所以我模拟了你的近似值:

1
2
3
4
5
6
set.seed(69)
measurement1 <- 1:1500
measurement2 <- 1:1500 + c(rnorm(50, 1200, 50), rnorm(1400, 0, 99), rnorm(50, -1400, 50))

df <- data.frame(measurement1, measurement2)
df <- df[df$measurement1 > 0 & df$measurement2 > 0, ]

所以现在我们只需要将每对测量值之间的绝对差值作为我们的着色变量:

1
2
3
4
5
6
7
library(ggplot2)

ggplot(df, aes(measurement1, measurement2)) +
  geom_line(aes(y = measurement1), size = 2, colour =”gold”) +
  geom_point(aes(colour = abs(measurement2 – measurement1))) +
  scale_colour_gradient(low =”orange”, high =”red”, name =”Difference”) +
  labs(y =”Adjusted.Function.Points”, x =”Functional.Size”)

></p>
<p>由 reprex 包 (v0.3.0) 创建于 2020-06-08</p>
<div class=

  • 哇,非常感谢!这太有帮助了!!!真的很感谢所有的帮助!!


来源:https://www.codenong.com/62267090/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_8784.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?