[R] ccomp Composition and ggtern plot...

Crump, Ron R.E.Crump at warwick.ac.uk
Thu Nov 23 12:44:24 CET 2017


> I would like to use compositions package with ggplot/ggtern, other
> composition classes of compositional package can be used with ggtern
> by converting to data frame but I could do anything with c(ount)comp
> class. Ggplot/ggtern can not recognise comp and also can not be converted > to data frame. Is there any other way to do this?

As Jeff pointed out, the help page says ccomp creates a vector
or matrix. But it assigns a class of 'ccomp', and there is no
obvious way to coerce this directly to a data.frame for use with
ggplot (but I'm not very good with classes so I may be wrong).

However, it does appear to be just a matrix(or vector) with a
class added (I presume to facilitate the provision of class
specific functions), so you can convert it to a matrix (vector)
with attr( my_ccomp, 'class' ) <- NULL and go from there.

eg

library(compositions)
data(SimulatedAmounts)
my_ccomp <- ccomp(sa.lognormals)
print(class(my_ccomp))
attr(my_ccomp,'class')<-NULL
print(class(my_ccomp))
my_ccomp_df <- as.data.frame(my_ccomp)
# or, as I've just seen in the code of plot.ccomp,
# my_ccomp_df <- as.data.frame(unclass(my_ccomp))

Regards,
Ron.


More information about the R-help mailing list