Reputation: 318
I'm trying to do a plot from a data.frame that contains positive and negative values and I cannot plot all points. Someone know, if is possible to adapt the code to plot all point?
example = data.frame(X1=c(-1,-0.5,1),X2=c(-1,0.7,1),X3=c(1,-0.5,2))
ggtern(data=example, aes(x=X1,y=X2,z=X3)) + geom_point()
Upvotes: 3
Views: 1140
Reputation: 10526
Well actually your points are getting plotted, but they lie outside the plot region.
Firstly, to understand why, each row of your data must sum to unity, else it will be coerced that way, therefore what you will be plotting is the following:
example = example / matrix(rep(rowSums(example),ncol(example)),nrow(example),ncol(example))
example
X1 X2 X3
1 1.000000 1.000000 -1.000000
2 1.666667 -2.333333 1.666667
3 0.250000 0.250000 0.500000
Now the rows sum to unity:
print(rowSums(example))
[1] 1 1 1
You have negative values, which are nonsensical in terms of 'composition', however, negative concentrations can still be plotted, as they will numerically represent points outside the ternary area, lets expand the limits and render to see where they lie:
ggtern(data=example, aes(x=X1,y=X2,z=X3)) +
geom_mask() +
geom_point() +
limit_tern(5,5,5)
Upvotes: 3