我有一个看似简单的问题,由于某种原因我无法找到任何信息。
我正在尝试使用从我的数据集的标准差导出的误差条创建一个简单的散点图。但是,有一些数据集只有一个点 - 因此sd函数返回nan。
当我尝试使用ggplot2中的数据时会出现问题,我收到以下错误:
错误:ggplot2不知道如何处理class uneval的数据
以下是我创建平均和标准差数据的代码:
avg_rxn <- rxn_data %>%
group_by(system, solvent_type, solvent_position) %>%
summarize(distance_mean = mean(distance),
distance_error = sd(distance),
energy_mean = mean(energy_rxn),
energy_error = sd(energy_rxn))
这是我生成情节的代码:
water_distance <- avg_rxn %>%
filter((system == "9h0m") | (system == "8h1m")) %>%
filter(solvent_type == "water") %>%
#filter(solvent_position == "axial") %>%
select(energy_mean, energy_error, system, solvent_position, distance_mean, distance_error)
ylimits = aes(ymax = energy_mean + energy_error, ymin = energy_mean - energy_error)
xlimits = aes(xmax = distance_mean + distance_error, xmin = distance_mean - distance_error)
water_distance_plot <- ggplot(data = water_distance, aes(solvent_position, x = distance_mean,
y = energy_mean, shape = solvent_position,
color = system)) +
geom_point(size = 5) +
geom_errorbar(ylimits, xlimits, width = 0.25) +
theme_few()
ggsave("figures/water_distance_plot.png", water_distance_plot)
我可以想象这个问题的几种不同的解决方案,但无法弄清楚如何实现它们。在计算avg_rxn时,nan值可以替换为0,或者ggplot2可以在计算误差条限制的算术期间简单地忽略nan值。
非常感谢任何帮助!
*编辑*
根据要求,这里有一些数据(包括有效的点和没有的点)。这些空格应该允许它被解释,然后保存为csv。
ID system geometry_number solvent_number solvent_position solvent_type energy_rxn 0h9m_1_1 0h9m 1 1等值甲醇38.91447 0h9m_1_2 0h9m 1 2等量甲醇42.31569 0h9m_1_3 0h9m 1 3等量甲醇43.06978 0h9m_1_4 0h9m 1 4轴向甲醇42.94058 0h9m_1_5 0h9m 1 5轴向甲醇40.79774 0h9m_1_6 0h9m 1 6轴向甲醇43.06764 0h9m_1_7 0h9m 1 7轴向甲醇43.45027 0h9m_1_8 0h9m 1 8轴向甲醇42.60882 0h9m_1_9 0h9m 1 9轴向甲醇45.0522 1h8m_1_1 1h8m 1 1等量甲醇41.40231 1h8m_1_2 1h8m 1 2等量甲醇43.22337 1h8m_1_3 1h8m 1 3等值甲醇41.43154 1h8m_1_4 1h8m 1 4轴向甲醇42.53526 1h8m_1_5 1h8m 1 5轴向甲醇43.18862 1h8m_1_6 1h8m 1 6轴向甲醇43.07718 1h8m_1_7 1h8m 1 7轴向甲醇43.00857 1h8m_1_8 1h8m 1 8轴向甲醇43.57557 1h8m_1_9 1h8m 1 9轴向水34.68406 1h8m_2_1 1h8m 2 1等量甲醇43.83503 1h8m_2_2 1h8m 2 2等量甲醇45.12783 1h8m_2_3 1h8m 2 3赤道水30.27222 1h8m_2_4 1h8m 2 4轴向甲醇40.47726 1h8m_2_5 1h8m 2 5轴向甲醇43.58034 1h8m_2_6 1h8m 2 6轴向甲醇44.02348 1h8m_2_7 1h8m 2 7轴向甲醇42.43128 1h8m_2_8 1h8m 2 8轴向甲醇46.02447 1h8m_2_9 1h8m 2 9轴向甲醇43.73061 2h7m_1_1 2h7m 1 1等量甲醇42.28647 2h7m_1_2 2h7m 1 2等量甲醇42.93061 2h7m_1_3 2h7m 1 3等量甲醇42.0748 2h7m_1_4 2h7m 1 4轴向甲醇43.55864 2h7m_1_5 2h7m 1 5轴向甲醇43.33525 2h7m_1_6 2h7m 1 6轴向甲醇44.1656 2h7m_1_7 2h7m 1 7轴向甲醇42.83685 2h7m_1_8 2h7m 1 8轴向水34.04387 2h7m_1_9 2h7m 1 9轴向水35.07239 2h7m_2_1 2h7m 2 1等摩尔甲醇41.44339 2h7m_2_2 2h7m 2 2等量甲醇43.847 2h7m_2_3 2h7m 2 3等量甲醇41.59372 2h7m_2_4 2h7m 2 4轴向甲醇43.49975 2h7m_2_5 2h7m 2 5轴向甲醇44.02411 2h7m_2_6 2h7m 2 6轴向水34.06499 2h7m_2_7 2h7m 2 7轴向甲醇44.79557 2h7m_2_8 2h7m 2 8轴向甲醇44.85728 2h7m_2_9 2h7m 2 9轴向水34.51222 2h7m_3_1 2h7m 3 1等量甲醇41.67581 2h7m_3_2 2h7m 3 2等量甲醇42.25084 2h7m_3_3 2h7m 3 3等量甲醇42.94723 2h7m_3_4 2h7m 3 4轴向甲醇43.55839 2h7m_3_5 2h7m 3 5轴向甲醇43.29994 2h7m_3_6 2h7m 3 6轴流水34.7908 2h7m_3_7 2h7m 3 7轴向甲醇44.08162 2h7m_3_8 2h7m 3 8轴流水35.26678 2h7m_3_9 2h7m 3 9轴向甲醇44.01194 2h7m_4_1 2h7m 4 1等量甲醇42.30547 2h7m_4_2 2h7m 4 2等量甲醇43.21565 2h7m_4_3 2h7m 4 3赤道水33.13139 2h7m_4_4 2h7m 4 4轴向甲醇44.7819 2h7m_4_5 2h7m 4 5轴向甲醇44.36447 2h7m_4_6 2h7m 4 6轴向甲醇42.84187 2h7m_4_7 2h7m 4 7轴向甲醇43.7597 2h7m_4_8 2h7m 4 8轴向甲醇42.16279 2h7m_4_9 2h7m 4 9轴向水33.87122 2h7m_5_1 2h7m 5 1等量甲醇43.05943 2h7m_5_2 2h7m 5 2等量甲醇42.42544 2h7m_5_3 2h7m 5 3赤道水32.6147 2h7m_5_4 2h7m 5 4轴向甲醇43.9089 2h7m_5_5 2h7m 5 5轴向甲醇43.74754 2h7m_5_6 2h7m 5 6轴向甲醇44.32521 2h7m_5_7 2h7m 5 7轴向水34.46159 2h7m_5_8 2h7m 5 8轴向甲醇44.44951 2h7m_5_9 2h7m 5 9轴向甲醇44.39225 2h7m_6_1 2h7m 6 1等摩尔甲醇42.45906 2h7m_6_2 2h7m 6 2赤道水33.08564 2h7m_6_3 2h7m 6 3赤道水32.82477 2h7m_6_4 2h7m 6 4轴向甲醇43.5979 2h7m_6_5 2h7m 6 5轴向甲醇43.62907 2h7m_6_6 2h7m 6 6轴向甲醇43.77689 2h7m_6_7 2h7m 6 7轴向甲醇43.35983 2h7m_6_8 2h7m 6 8轴向甲醇44.43013 2h7m_6_9 2h7m 6 9轴向甲醇44.49385 3h6m_1_1 3h6m 1 1等值甲醇44.74621 3h6m_1_2 3h6m 1 2等量甲醇44.08081 3h6m_1_3 3h6m 1 3等量甲醇41.49557 3h6m_1_4 3h6m 1 4轴向甲醇42.18926 3h6m_1_5 3h6m 1 5轴向甲醇44.80554 3h6m_1_6 3h6m 1 6轴向甲醇46.12343 3h6m_1_7 3h6m 1 7轴向水32.94014 3h6m_1_8 3h6m 1 8轴向水35.29087 3h6m_1_9 3h6m 1 9轴流水35.75008