为什么GGPLOT突然将Y轴数的甲酸变为指数?
I found various posts solving the issue to change the y-axis from exponential back to a noraml decimal:
,但我只想知道为什么y轴值格式从0.4到4.000000e-01,当我更改我的时代码来自 scale_y_continous(breaks = seq(-0.2,0.4,0.05)))
to scale> scale_y_continous(breaks = seq(-0.3,0.4,0.05))
????我只将-0.2更改为-0.3,我不认为它应该更改y轴值的格式。
代码复制问题。
ISD2 = data.frame(Distance = c(50,150,250,350,450,550,650,750,850,950,50,150,250,350,450,550,650,750,850,950),
Related = c(-0.00036,-0.02968,-0.02685,-0.05379,0.01345,-0.03163,-0.00826,-0.12643,-0.05609,0.10906,0.03957,-0.02621,-0.01709,-0.03086,-0.06208,-0.00839,-0.03827,0.01823,-0.01130,-0.02848),
R_LCI = c(-0.08,-0.06,-0.06,-0.05,-0.05,-0.05,-0.07,-0.10,-0.14,-0.14,-0.28,-0.06,-0.05,-0.05,-0.05,-0.05,-0.06,-0.09,-0.12,-0.23),
R_UCI = c(0.04,0.01,0.01,0.00,0.01,0.01,0.03,0.09,0.16,0.40,0.03,0.01,0.00,0.00,0.00,0.00,0.02,0.05,0.08,0.23),
Sex = c('M','M','M','M','M','M','M','M','M','M','F','F','F','F','F','F','F','F','F','F'))
ggplot(aes(x=Distance, y = Related, color=Sex),data = ISD) +
stat_smooth(method = "lm", se = F) +
geom_point(position=position_dodge(width=30), size = 4) +
geom_point(aes(x=0, y=0.37), color = "#DC3220",size=4) +
geom_point(aes(x=5, y=0.28), color = "#005AB5",size=4) +
geom_errorbar(aes(ymin=R_LCI, ymax=R_UCI), position=position_dodge(width=30), width=20) +
scale_x_continuous("Distance (m)", breaks = seq(0,1000,100), limit = c(0,1000), expand = c(0,20)) +
scale_y_continuous("Relatedness", breaks = seq(-0.3,0.35,0.05)) +
annotate("text", label = "Adults Only", x =800, y =.35, size = 6) +
scale_color_manual(values = c("#DC3220","#005AB5"))```
I found various posts solving the issue to change the y-axis from exponential back to a noraml decimal:
avoid scientific notation x axis ggplot
How do I change the formatting of numbers on an axis with ggplot?
But I just want to know are WHY the y-axis value format goes from 0.4 to 4.000000e-01 when I change my code fromscale_y_continuous(breaks = seq(-0.2,0.4,0.05))
to scale_y_continuous(breaks = seq(-0.3,0.4,0.05))
??? I only changed -0.2 to -0.3, I wouldn't think it should change the format of the y-axis values.
Code to reproduce the issue.
ISD2 = data.frame(Distance = c(50,150,250,350,450,550,650,750,850,950,50,150,250,350,450,550,650,750,850,950),
Related = c(-0.00036,-0.02968,-0.02685,-0.05379,0.01345,-0.03163,-0.00826,-0.12643,-0.05609,0.10906,0.03957,-0.02621,-0.01709,-0.03086,-0.06208,-0.00839,-0.03827,0.01823,-0.01130,-0.02848),
R_LCI = c(-0.08,-0.06,-0.06,-0.05,-0.05,-0.05,-0.07,-0.10,-0.14,-0.14,-0.28,-0.06,-0.05,-0.05,-0.05,-0.05,-0.06,-0.09,-0.12,-0.23),
R_UCI = c(0.04,0.01,0.01,0.00,0.01,0.01,0.03,0.09,0.16,0.40,0.03,0.01,0.00,0.00,0.00,0.00,0.02,0.05,0.08,0.23),
Sex = c('M','M','M','M','M','M','M','M','M','M','F','F','F','F','F','F','F','F','F','F'))
ggplot(aes(x=Distance, y = Related, color=Sex),data = ISD) +
stat_smooth(method = "lm", se = F) +
geom_point(position=position_dodge(width=30), size = 4) +
geom_point(aes(x=0, y=0.37), color = "#DC3220",size=4) +
geom_point(aes(x=5, y=0.28), color = "#005AB5",size=4) +
geom_errorbar(aes(ymin=R_LCI, ymax=R_UCI), position=position_dodge(width=30), width=20) +
scale_x_continuous("Distance (m)", breaks = seq(0,1000,100), limit = c(0,1000), expand = c(0,20)) +
scale_y_continuous("Relatedness", breaks = seq(-0.3,0.35,0.05)) +
annotate("text", label = "Adults Only", x =800, y =.35, size = 6) +
scale_color_manual(values = c("#DC3220","#005AB5"))```
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可以直接简化这两个序列的比较:
看起来像是与此相关的浮点问题:
为什么这些数字不相等?。
快速修复可能是使用
或
This can be further simplified to a comparison of the two sequences directly:
Looks like a floating point issue related to this:
Why are these numbers not equal?.
Quick fix could be to to use
or