Geom_point 和 ggboxplot 以及 ggpair 在 ggplot 中错误地对所有绘图点进行了配对

尼尔劳伦斯

我正在尝试一些简单的箱线图,但注意到我在数据框中得到的点只是在 ggplot 中绘制不正确,在所有上述类型的图中。

我的数据是

structure(list(rownum = 1:74, Device = c("Dexcom", "Dexcom", 
"Dexcom", "Dexcom", "Dexcom", "Dexcom", "Dexcom", "Dexcom", "Dexcom", 
"Dexcom", "Dexcom", "Dexcom", "Dexcom", "Dexcom", "Dexcom", "Libreview", 
"Libreview", "Libreview", "Libreview", "Libreview", "Libreview", 
"Libreview", "Libreview", "Libreview", "Libreview", "Libreview", 
"Libreview", "Libreview", "Diasend Manual", "Diasend Manual", 
"Diasend Manual", "Diasend Manual", "Diasend Manual", "Diasend Manual", 
"Diasend Manual", "Diasend Manual", "Diasend CGM", "Diasend Manual", 
"Diasend Manual", "Diasend Manual", "Diasend Manual", "Diasend Manual", 
"Diasend CGM", "Diasend CGM", "Diasend Manual", "Diasend Manual", 
"Diasend Manual", "Diasend Manual", "Diasend CGM", "Diasend Manual", 
"Diasend Manual", "Diasend CGM", "Diasend Manual", "Diasend Manual", 
"Diasend Manual", "Diasend Manual", "Diasend Manual", "Diasend CGM", 
"Diasend Manual", "Diasend CGM", "Diasend Manual", "Diasend Manual", 
"Diasend Manual", "Diasend CGM", "Diasend Manual", "Diasend CGM", 
"Diasend Manual", "Diasend Manual", "Diasend Manual", "Diasend Manual", 
"Diasend Manual", "Diasend Manual", "Diasend CGM", "Diasend Manual"
), PREMean = c(10.0484850182022, 7.84715557883709, 7.28766699205132, 
8.47011442894507, 10.7497970736388, 8.6565711351755, 12.2666572965045, 
12.8489327534292, 9.38152123552124, 9.82593283758822, 9.25191807020791, 
10.590004260355, 10.1991015796402, 8.11500023112837, 9.3887371146612, 
9.05289979902383, 16.3938994229184, 11.2269812823576, 8.46589333710567, 
9.45301483336544, 9.654521175124, 9.17169712793734, 5.90663637838715, 
15.1026720647773, 8.73502786461873, 12.515518913676, 10.2021609195402, 
8.88323924469535, 9.138, 10.5977853492334, 14.7827906976744, 
10.9643874643875, 8.04525252525253, 9.2234693877551, 9.2234693877551, 
13.4109826589595, 8.65916169339799, 9.07101449275362, 10.7026923076923, 
17.9097799511002, 6.05655339805825, 7.24913151364764, 7.84826142795985, 
11.6334796926454, 10.0795389048991, 9.63545878693624, 11.7388888888889, 
11.3917218543046, 8.11740335319385, 9.41461318051576, 12.9295681063123, 
10.2035994083164, 7.68975155279503, 10.249885583524, 5.79714285714286, 
10.0638826185102, 8.44704049844237, 10.6952513150205, 9.36492957746479, 
9.83008799318762, 9.6688654353562, 8.00041753653445, 9.26, 9.38389756944444, 
8.55568181818182, 8.63457241816674, 8.12372881355932, 9.84208494208494, 
11.28828125, 9.04013157894737, 11.6740659340659, 9.61797752808989, 
13.8315843798383, 10.1719101123596), POSTMean = c(8.19190208049315, 
7.61158509359437, 7.20120148352596, 8.57923580164976, 10.6268789167925, 
8.37193152150653, 12.3593220150292, 13.9380512091038, 9.30225121492054, 
8.19597861420017, 8.73307014253563, 8.23531795760565, 10.4691064145347, 
8.78835006435006, 9.48096681373489, 9.12521085925145, 13.1253985706432, 
10.2115876974231, 7.65094314018184, 11.1021567021567, 12.3527429320352, 
8.74159058145123, 6.82408707865169, 9.2207729468599, 8.33679846938776, 
11.2045885361817, 12.2492643845594, 8.41001977587343, 8.24191419141914, 
10.7707317073171, 12.2390334572491, 8.28022598870056, 7.67814207650273, 
9.48614130434783, 9.48614130434783, 11.0455128205128, 8.36162310181728, 
10.2825581395349, 10.1807407407407, 16.3283333333333, 7.56851851851852, 
6.80612244897959, 7.6510029661656, 12.1434984833165, 12.2157894736842, 
11.2797101449275, 19.1619047619048, 13.2472361809045, 8.87069342340552, 
8.40763888888889, 13.5286956521739, 10.4632632632633, 8.76877470355731, 
10.6271903323263, 8.2667701863354, 8.61640378548896, 6.96209386281588, 
8.29738799201886, 8.51794871794872, 8.10574666733237, 8.43217993079585, 
7.7244635193133, 13.9224137931034, 9.19426699426699, 8.15335753176044, 
8.30695218383485, 5.89611231101512, 9.45526315789474, 9.406875, 
9.78860759493671, 9.33200934579439, 9.406875, 11.2342145015106, 
11.2984126984127)), row.names = c(NA, -74L), na.action = structure(c(`19` = 19L, 
`30` = 30L, `38` = 38L, `39` = 39L, `42` = 42L, `44` = 44L, `51` = 51L, 
`62` = 62L, `79` = 79L, `84` = 84L), class = "omit"), class = c("tbl_df", 
"tbl", "data.frame"))

然后

ggplot(data, aes(x=PREMean, y=POSTMean)) + geom_point()

绘制一些明显过低的点 - 小于 5。没有一个数字小于 5。

使用 ggboxplot 和 ggpaired 绘图也给了我太低的分数。

我正在扯头发,我只是不明白为什么这些点的绘制明显不正确?请帮忙,谢谢。

彼得

正如@RichardTelford 所说,您的情节符合预期。

我已将这两个图添加到答案中,以演示ggplot's默认轴比例和用户定义比例之间的差异

ggplot 不知道您将如何解释轴:它只取每个轴的最小值和最大值并将它们拟合到可用空间,并通过标记刻度线来尽其所能。ggplot 依赖于读者来锻炼,在默认版本使用你的情况下,datax 轴上的次网格线代表 2.5,因此 x 原点略大于 5。

如果您想明确轴值和中断,则必须告诉 ggplot 要打印什么。您有很大的灵活性:您可以设置限制、休息时间和规模……

如果您想要一系列图形的特定限制和中断对,那么您最好创建一个为您执行此操作的函数;不过,这是另一个问题的主题;你可以看看这个答案,它将比例从 0设置为数据的限制:在 ggplot 中设置 y 轴中断


library(ggplot2)
library(patchwork)

p1 <- ggplot(data, aes(x=PREMean, y=POSTMean)) +
  geom_point()+
  ggtitle("Default axis scales")


p2 <- ggplot(data, aes(x=PREMean, y=POSTMean)) +
  geom_point()+
  scale_x_continuous(limits = c(0,20))+
  scale_y_continuous(limits = c(0,20))+
  ggtitle("Defined axis scales")


p1/p2

reprex 包(v0.3.0)于 2020 年 6 月 27 日创建

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

带有ggplot2和geom_point的图例

ggplot:geom_point中的颜色,填充和大小

使用geom_point()和geom_line()进行多个系列的ggplot中的图例错误

ggplot方面和条件geom_point

在ggplot(R)中分离geom_point和geom_path绘图图层

ggplot2中带有geom_line和geom_point的图例

使用geom_bar和geom_point控制ggplot中的图例

由“ ggpair”和“ ggplot”并排生成的图

有人可以解释ggplot和geom_point之间的区别吗?

为ggplot2中的负值和正值在geom_point中设置不同的颜色

如何在ggplot2中获取堆叠的geom_bar和geom_point的通用图例?

添加geom_point和geom_line进行绘图

R ggplot2:如何绘制具有纯色和透明笔触并根据颜色着色的geom_point?

ggplot2:合并geom_line,geom_point和geom_bar的图例

ggplot2 geom_point具有图案填充

如何更改geom_point中的颜色或ggplot中的线

从图例中删除ggplot2的geom_point图标

增加ggplot geom_point中的最小点大小

如何减少ggplot中geom_point()之间的相对距离

ggplot2 2.0.0中的geom_point边界

ggplot中的自定义形状(geom_point)

ggplot图例(geom_point)中的空白条目?

ggplot2 中的振幅线 + geom_point

geom_point {ggplot2}中的alpha值

在ggplot2中使用geom_smooth()和geom_point()时显示带有日期的x轴标签

geom_point中的着色和标记点

ggplot2:如何将geom_line和geom_point的图层与错误栏组合在一起

ggplot2:将geom_line和geom_point组合在一起的图形中的坐标图例

ggplot上geom_point和geom_smooth的不同颜色比例