r - 尝试在 R ggplot 中绘制模拟数据会在绘图左侧产生一个奇怪的灰色块,我该怎么办?
问题描述
我正在尝试为我的论文的统计数据模拟一些数据,我觉得我在这方面做得很好,我对 R 没有那么丰富的经验,所以它可能比必要的时间长得多。我正在尝试将这些数据绘制在散点图中,但它正在努力解决它,我真的不知道如何解释它,但是图左侧有一个巨大的灰色块并且数据没有按顺序排列( 105 天 => 14 天 => 21 天)。Base R 处理得很好,但 ggplot 只是疯了。我该怎么办?
奇怪的事情出现了,最高的 x 值是第一个,然后是最低的:
dualex <- cbind.data.frame(
rbind(cbind(rep(c(14,21,28,35,42,49,56,63,70,77,84,91,98,105), each = 13),
round(rnorm(n = 182, mean = 20, sd = 2), 4), rep('C', 182)),
cbind(rep(c(14,21,28,35,42,49,56,63,70,77,84,91,98,105), each = 13),
round(rnorm(n = 182, mean = 19.8, sd = 2),4), rep('T1',182)),
cbind(rep(c(14,21,28,35,42,49,56,63,70,77,84,91,98,105), each = 13),
round(rnorm(n = 182, mean = 18.5, sd = 2),4), rep('T2',182)),
cbind(rep(c(14,21,28,35,42,49,56,63,70,77,84,91,98,105), each = 13),
round(rnorm(n = 182, mean = 18, sd = 2),4), rep('T3', 182)),
cbind(rep(c(14,21,28,35,42,49,56,63,70,77,84,91,98,105), each = 13),
round(rnorm(n = 182, mean = 17.4, sd = 2),4), rep('T4', 182))),
rbind(cbind(rep(c(14,21,28,35,42,49,56,63,70,77,84,91,98,105), each = 13),
round(rnorm(n = 182, mean = 0.35, sd = 0.02),4), rep('C', 182)),
cbind(rep(c(14,21,28,35,42,49,56,63,70,77,84,91,98,105), each = 13),
round(rnorm(n = 182, mean = 0.34, sd = 0.02),4), rep('T1',182)),
cbind(rep(c(14,21,28,35,42,49,56,63,70,77,84,91,98,105), each = 13),
round(rnorm(n = 182, mean = 0.32, sd = 0.02),4), rep('T2',182)),
cbind(rep(c(14,21,28,35,42,49,56,63,70,77,84,91,98,105), each = 13),
round(rnorm(n = 182, mean = 0.28, sd = 0.02),4), rep('T3',182)),
cbind(rep(c(14,21,28,35,42,49,56,63,70,77,84,91,98,105), each = 13),
round(rnorm(n = 182, mean = 0.23, sd = 0.02),4), rep('T4',182))),
rbind(cbind(rep(c(14,21,28,35,42,49,56,63,70,77,84,91,98,105), each = 13),
round(rnorm(n = 182, mean = 0.085, sd = 0.004),4), rep('C', 182)),
cbind(rep(c(14,21,28,35,42,49,56,63,70,77,84,91,98,105), each = 13),
round(rnorm(n = 182, mean = 0.083, sd = 0.004),4), rep('T1',182)),
cbind(rep(c(14,21,28,35,42,49,56,63,70,77,84,91,98,105), each = 13),
round(rnorm(n = 182, mean = 0.078, sd = 0.004),4), rep('T2',182)),
cbind(rep(c(14,21,28,35,42,49,56,63,70,77,84,91,98,105), each = 13),
round(rnorm(n = 182, mean = 0.28, sd = 0.02),4), rep('T3',182)),
cbind(rep(c(14,21,28,35,42,49,56,63,70,77,84,91,98,105), each = 13),
round(rnorm(n = 182, mean = 0.070, sd = 0.004),4), rep('T4',182))))
dualex[,c(3,4,6,7)] <- NULL
colnames(dualex) <- c('Day', 'Chl', 'Flav', 'Anth', 'Treatment')
#ggplot going crazy
ggplot(data = dualex, mapping = aes(x = Day, y = Chl)) + geom_point()
#base R takes it fine
plot(dualex$Day, dualex$Chl)
解决方案
推荐阅读
- sql-server - 通过 SSIS 将数据从 Excel (xlsx) 文件加载到 SQL 表时出现科学记数法问题
- java - 多行 Snakeyaml
- javascript - 在 Javascript 中为 Acrobat 存储和检索数据
- list - 将列表中的文本设置为文本小部件颤动
- python - python - 如何使用python中的循环减去满足某些条件的csv文件中的值?
- node.js - 将请求转发到内部服务 lambda AWS
- java - 无法定义以 keycloak 开头的属性
- javascript - 如何获取css中的属性数量
- cypress - 在 cypress 中键入变量,然后按 enter
- django - 在 `CreateView` 中向表单添加数据