免责声明:R 的新手。
你好!我正在尝试使用该ggtern
软件包绘制水化学样品的三元图。尝试运行以下代码会得到标题错误。
require(ggtern)
datos = read.csv("Li, B, Cl.csv", header = T, sep = ";", stringsAsFactors = FALSE)
names(datos) <- c("Muestra", "Li", "B", "Cl")
x11()
plot <- ggtern(data = datos, mapping = aes(x = as.numeric(datos[["Li"]]), y = as.numeric(datos[["Cl"]]), z = as.numeric(datos[["B"]]))) + geom_point()
plot
据我了解,有一些低级函数需要一个原子向量,但我给出ggtern
了一个 data.frame 作为输入(通过检查str()
)。
一旦执行,脚本就什么也不画了。我的数据格式如下,但以分号分隔:
Muestra Li B Cl
XYA3030 2.321334755 3.017842551 94.66082269
XEP3609 9.436334248 45.43581846 45.12784729
XEP3606_1 10.12604478 62.68726944 27.18668578
XEP3606_2 5.18367492 34.94305194 59.87327314
XEP3611 5.859786577 18.8098607 75.33035272
XEP3613 13.60173875 49.1191375 37.27912375
XEP3612 13.11960754 27.07316925 59.80722321
XEP3608 6.473636887 15.58523589 77.94112722
XEP3543 16.93515603 46.59573787 36.4691061
正如评论中所建议的,这是“dput(datos)”输出。
> dput(datos)
structure(list(Muestra = c("XYA3030", "XEP3609", "XEP3606_1",
"XEP3606_2", "XEP3611", "XEP3613", "XEP3612", "XEP3608", "XEP3543"
), Li = c(2.321334755, 9.436334248, 10.12604478, 5.18367492,
5.859786577, 13.60173875, 13.11960754, 6.473636887, 16.93515603
), B = c(3.017842551, 45.43581846, 62.68726944, 34.94305194,
18.8098607, 49.1191375, 27.07316925, 15.58523589, 46.59573787
), Cl = c(94.66082269, 45.12784729, 27.18668578, 59.87327314,
75.33035272, 37.27912375, 59.80722321, 77.94112722, 36.4691061
)), class = "data.frame", row.names = c(NA, -9L))
更新:尝试了我能想到的最简单的代码,但仍然没有运气。我错过了一些基本的东西吗?
library(ggtern)
datos = read.csv("Li_B_Cl.csv", header = T, sep = ";", stringsAsFactors = FALSE)
ggtern(data = datos, mapping = aes(x = Li, y = Cl, z = B)) + geom_point()
更新 2:清除 RStudio 会话和包,重新安装 ggtern 和 ggplot2,然后运行简单代码。没运气。这是错误后的回溯:
> datos = read.csv("Li_B_Cl.csv", header = TRUE, sep = ";", stringsAsFactors = FALSE)
> ggtern(data = datos, mapping = aes(x = Li, y = Cl, z = B)) + geom_point()
Error: $ operator is invalid for atomic vectors
> traceback()
17: transform_position(data, panel_params$x$rescale, panel_params$y$rescale)
16: f(...)
15: self$super()$super()$transform(data, scale_details)
14: f(..., self = self)
13: self$transform(ex, scale_details)
12: .get.tern.extremes(self, list(x.range = self$limits$x, y.range = self$limits$y))
11: f(..., self = self)
10: self$coord$setup_panel_params(scale_x, scale_y, params = self$coord_params)
9: (function (scale_x, scale_y)
{
self$coord$setup_panel_params(scale_x, scale_y, params = self$coord_params)
})(dots[[1L]][[1L]], dots[[2L]][[1L]])
8: mapply(FUN = f, ..., SIMPLIFY = FALSE)
7: Map(setup_panel_params, scales_x, scales_y)
6: f(..., self = self)
5: layout$setup_panel_params()
4: ggplot_build.ggplot(x)
3: ggplot_build(x)
2: print.ggplot(x)
1: (function (x, ...)
UseMethod("print"))(x)