问题
ggtern output
I am trying to plot the following data
> foo
Resp A B C
1 1.629 0.3333333 0.3333333 0.3333333
2 1.734 0.1666667 0.6666667 0.1666667
3 1.957 0.0000000 1.0000000 0.0000000
4 1.778 1.0000000 0.0000000 0.0000000
5 1.682 0.6666667 0.1666667 0.1666667
6 1.407 0.1666667 0.1666667 0.6666667
7 1.589 0.0000000 0.5000000 0.5000000
8 1.251 0.0000000 0.0000000 1.0000000
9 1.774 0.5000000 0.5000000 0.0000000
10 1.940 0.5000000 0.0000000 0.5000000
>
Using
ggtern() +
geom_interpolate_tern(
data = foo,
mapping = aes(y = A,x = B,z = C,value=Resp),method='auto',base = "identity",n=200)
The lack of a smooth interpolation is something I can't seem to get rid of twicking the function parameters. I actually have multiple response arrays for this simplex and they all present the non-smoothness in the output.
Am I missing something about interpolation using ggerg
and geom_interpolate_tern
?
回答1:
This is due to the fact that R doesn't nativly anti-alias on Windows.
foo <- structure(list(Resp = c(1.629, 1.734, 1.957, 1.778, 1.682, 1.407,
1.589, 1.251, 1.774, 1.94), A = c(0.3333333, 0.1666667, 0, 1,
0.6666667, 0.1666667, 0, 0, 0.5, 0.5), B = c(0.3333333, 0.6666667,
1, 0, 0.1666667, 0.1666667, 0.5, 0, 0.5, 0), C = c(0.3333333,
0.1666667, 0, 0, 0.1666667, 0.6666667, 0.5, 1, 0, 0.5)), .Names = c("Resp",
"A", "B", "C"), class = "data.frame", row.names = c("1", "2",
"3", "4", "5", "6", "7", "8", "9", "10"))
You can fix this by using a different graphics device to render.
require(Cairo)
require(ggplot2)
require(ggtern)
g1 <- ggtern() +
geom_interpolate_tern(
data = foo,
mapping = aes(y = A,x = B,z = C,value=Resp),method='auto',base = "identity",n=200)
ggsave("Tern.png", width=12, height=8, dpi = 300, type = "cairo-png")
Or as SVG
# note that you don't need Cairo to render the .svg
ggsave("Tern.svg", width=12, height=8, dpi = 300)
来源:https://stackoverflow.com/questions/46204307/r-ggtern-geom-interpolate-tern-why-is-the-plot-not-smooth-at-the-symmetry-l