‘ggtern’ is a software package for the statistical computing language R. It is an extension to ggplot2 [1] specifically for the plotting of ternary diagrams.
Ternary diagrams are Barycentric plots w/ three variables, and, they are commonly used within the fields of chemistry, petrology, mineralogy, metallurgy, materials-science, genetics and game-theory, amongst others. Whereas a simplex diagram is the general case for , in
dimensions, the ternary diagram is the specific case when
(producing
vertices).
With the exception of the work by Sean Mulcahy [2] and Darren Wilkinson [3], there are very few resources on the internet where ggplot2 [1] has been used as a platform for rendering such diagrams, ggtern attempts to bridge this gap, and has since been used within a number of publications as a direct result.
If you are familiar with the syntax of ggplot2, then using ggtern should be a breeze, without too much trouble, it is quite easy to produce publication quality ternary diagrams such as the one immediately below:
References
@Book{wickham,
Title = {ggplot2: Elegant Graphics for Data Analysis},
Author = {Wickham, Hadley},
Publisher = {Springer-Verlag},
Year = {2009},
Owner = {Nick Hamilton},
Timestamp = {20131123}
}
[Bibtex]
@Electronic{mulcahy,
Title = {Ternary Plots in R},
Author = {Mulcahy, S.R.},
HowPublished = {Website},
Language = {English},
Url = {http://srmulcahy.github.io/2012/12/04/ternary-plots-r.html},
Owner = {Nick Hamilton},
Timestamp = {20131222}
}
[Bibtex]
@Electronic{wilkinson,
Title = {Ternary Plots in GGPLOT/R},
Author = {Wilkinson, D.},
HowPublished = {Website},
Language = {English},
Url = {http://wilkinsondarren.wordpress.com/2013/09/10/ternary-plots-in-ggplotr/},
Owner = {Nick Hamilton},
Timestamp = {20131222}
}
Nick,
thanks a lot for this R package. It is fantastic. I have been using your package for the last five years now and use it a lot for my work. Thanks
No problem Bastian, Great to hear this kind of feedback. Cheers.
Dear Nicholas Hamilton,
I’am installing ggtern package, but I met the difficulty.
I cannot intalled even I try in many ways.
(Error in get(x, envir = ns, inherits = FALSE) :
objet ‘expand_default’ introuvable
Error : unable to load R code in package ‘ggtern’
Execution stopped:
ERROR: lazy loading failed for package ‘ggtern’
* removing ‘/home/an/R/x86_64-pc-linux-gnu-library/3.6/ggtern’
Warning in install.packages :
installation of package ‘ggtern’ had non-zero exit status
The downloaded source packages are in
‘/tmp/RtmpRr7Qbz/downloaded_packages’)
Could you help me to fix it please!
Thank you very much!
I’m looking forward to hearing from you soon!
Best regards
An
Wonderful package – is there any way to combine the plot with a phase diagram graphic within ggtern? Something akin to this?
Not sure what you mean, can you provide an example?
Sorry, the link didn’t paste before – basically just a .png or other image graphic underneath the ggtern diagram. Here is the link again:
https://www.researchgate.net/figure/270664107_fig17_FeO-Al2O3-SiO2-ternary-diagram-after-Muan-1957-The-Baojia-slag-samples-mostly-plot-in
It would be tricky to overlay, however, there is nothing stopping the entire phase diagram being drawn in ggtern…. if you have the time….
Scott, the working version (v2.1.1) currently on my bitbucket account has a new geometry for including raster images. Actually this was quite a bit easier than I had thought. Here is an example:
Until I make another update to CRAN, you will need to clone the git repo and install from source.
That’s awesome! Thanks so much for that – this is such a great package. Thanks for putting it out there.
Quick follow up question – since this is just for raster images (annotation_raster instead of annotation_custom), is there a way to scale the image to fit the parameters of the ternary diagram? Ordinarily, I’d use a grob and set the lims to Inf to get it to auto-scale using annotation_custom. Is that possible with the adjustments you’re made using just raster images? At the moment I have a beautiful phase diagram behind my data points, but the image is ~75% the size of the ggtern plot.
Scott, you need to tweak the xmin, xmax, ymin, ymax values. Basically, if you use an image which has NO whitespace external to the bounding rectangle defined by the three apexes, then xmin = 0, xmax = 1, ymin = 0, ymax = 1 should place the image correctly.
Thank you so much Nicholas for creating this package and also for including raster images. Although it was easy to find your package as a tool for drawing Ternary diagrams, it took me a long time to find out it is capable of including raster images. It would be great if you put this example somewhere else rather than comments, so other users also find out about this cool feature of the tool 😉
I’m just found this, but are you able to make contours similar to a Response Surface Mixture Design of Experiment (e.g. Minitab)? If so that would be great to implement in a real DoE package for Chemists and ChemEs
Max, can you post an example of what you mean please?
I would also love to see an implementation of a ternary, or better n-dimensional, response surface plot. The response surface methodology is useful for finding the optimal component or process combinations. An example of this kind of ternary response surface plot is here: https://goo.gl/images/m9Qsn8
Hey Nicholas, this is an awesome package! I’m using it to create plots for a scientific artictle right now.
However, it seems that I came across an error: I have a plot where I need the grid lines on top, so I’m using the “theme_gridsontop()” option (or tern.panel.grid.ontop = TRUE in theme options). But when I do this, the axis labels don’t get plotted anymore! If I remove that option, the labels are plotted just fine. Here is an example plot that shows you what I mean – I can only get the left or the right version, not both – but I have been able to create plots with both options before.
Try upgrading, works fine for me, may be a bug in a previous version, I recently re-worked all the axis-rendering routines.
Dear Nicholas,
Thank you very much for the package! We are working with it, but applying to environmental data – sterols in sediments – in order to find something about where the organic matter comes from.We are from UFPR, a University in Brazil.
So, as beginners we find a lot of troubles! We could plot it, ok, very cool graphic!! But can’t find a way to label each dot, i.e. with its codes or sample numbers. Tried it in many ways. I imagine this is a basic thing… But can’t achieve this.
Could you please provide us a basic script that could do that in a ternplot (label each data point) in order to use it as a guide? Maybe you already have it done but could not find anywhere.
Thank you very much! Best regards!
Maria, Sure, try the following, where there are two (2) methods of labelling demonstrated:
Dear Nicholas,
Thank you very much! My friend could achieve it!! Not my credits, I make it clear, ok 🙂
Very cool!
Best regards
Hello
I have plotted a triangular plot,that three dimensions of which represent three herbal strategies. One dimension represents the strategy of C (competitive plant), the second dimension “S” (stress tolerant plants) and the third dimension”R” (ruderal plants), as you can see in the image below, the points on it represent the plant species. Now I am trying to write name of the plant species outside the triangle and connect with the arrow to the corresponding point. How do I do this work? Many thanks in advance as it would help me a lot in my work.
Dear Nicholas,
Tried to post the graphic here but I couldn’t, so I posted the graphic in my blog. Sorry for the bad blog! Don’t update it for long time. But just in case…
https://marinareback.wordpress.com/
Best regards!! Thanks again.
No problems Marina, Glad it worked out!. Not a big issue, but I noticed that you (probably) brought the grids to the front (via theme_gridsontop)? Is there a particular reason for this? Usually this can be desirable for the special case where one is plotting polygon geometries that cover the entire (or a large proportion of the) surface. In your situation, some of the grid lines have divided the points, which can be misleading.
Alternatively, here is an another approach which you might take:
Which produces the following:
Dear Nicholas,
In fact we needed do fix it, the gridlines were above the dots for mistake, but I don’t know why. Now it is perfect. Thank you so very much!
I’ll ask for my friend to post the script she used, just in case.
Regards, have a nice week!
P.S. the diagram posted on my blog (with somo data from PAHs concentrations in sediments)
Hello Nicholas,
I was wondering how can I do two things with the ggtern package:
1. If I have a table with 4 variables (x,y,z, and value), how can I make a triangular heatmap? I could make a regular heatmap in ggplot, but all the geometries seem to fail with ggtern
2. Is it possible to use factors instead of numeric values for the three axes?
Thank you in advance!
Alex, there is no geometry for ternary heatmaps yet, so you will have to take an approach like this: http://stackoverflow.com/questions/26221236/ternary-heatmap-in-r
In regards to item 2, the answer is no, ternary diagrams are representations of compositional data, factors have no bearing other than for grouping sets of data, certainly not when it comes to positioning.
The geometries are limited, due to the simplex nature of the coordinates. Heatmap is something I am planning to add, but I am not sure on the timeline. In regards to using factors on the sclaes, how would you propose that this would work, given that each point on the surface represents a composition. If you are simpley wanting to change the labels on the axes, then this can be done no problems.
hexagonal or triangular heatmap is now included from version 2.2.2 and beyond.
Hi Nicholas, great work on ggtern!
I am not able to update the package (both from CRAN and git), I always get this error:
** preparing package for lazy loading
Error in get(x, envir = ns, inherits = FALSE) :
object "new_panel" not found
error : unable to load R code in package ‘ggtern’
ERROR: lazy loading failed for package ‘ggtern’
* removing ‘/path_to/R/x86_64-pc-linux-gnu-library/3.2/ggtern’
The downloaded source packages are in
‘/tmp/RtmpCfblTa/downloaded_packages’
Warning message:
In install.packages("ggtern") :
installation of package ‘ggtern’ had non-zero exit status
</code>
The older version of ggtern would not work since ggplot2 complains about the older ggproto version. Any hints?
Cheers,
Marco
Digging a little more, it appears that the status on CRAN reports that currently ggtern is only completing the check and install on OSX, and fails on Windows and Linux (which I’m on).
ftp://r-project.org/pub/R/web/checks/check_results_ggtern.html
https://www.r-project.org/nosvn/R.check/r-release-linux-x86_64/ggtern-00install.html
Marco, this is an issue with the latest ggplot version. I havn’t had the time to ensure compatability, try reverting to ggplot 2.1.X, apologies.
Understood. Any timeframe for a possible fix on your side? Just asking, I’ll manage with the workaround.
Marco, I have just submitted to cran, cant imagine there will be any issues. You can download and install from source, from my bitbucket account. May be a few bugs, let me know if you have issues.
Dear Nicholas,
Thank you very much for the wonderful package!
I would like to use your package.
But, I have a trouble. I can not run ggtern() function, because of an error: “GeomMask was built with an incompatible version of ggproto. Please reinstall the package that provides this extension.” How do you solve the problem?
Environment: R 3.3.2
Installed/required packages: ggplot2, ggtern
Best regards.
Takahiro
Dear Nicholas,
I am sorry to disturb your busy time.
I coped with the problem by downloading and installing the old ggplot2 package.
https://cran.r-project.org/src/contrib/Archive/ggplot2/
install.packages(“C:\\…\\ggplot2_2.1.0.tar.gz”, repos = NULL, type = “source”)
I appreciate your continuous support.
Takahiro
Takahiro, have submitted update to CRAN, you can download and install from source from my bitbucket account.
Dear Nicholas,
I have checked/installed the updated package .Thank you very much for your quick support. Best regards, Takahiro
Cheers.
Dear Nicholas,
Thank you for your contribution of this useful ggtern package.
I encounter the same problem as Takahiro today
It did work until I update my R software this morning. (from R-3.2.3 to R-3.3.2)
It shows the following warning message when executing.
“GeomMask was built with an incompatible version of ggproto.
Please reinstall the package that provides this extension.
Is there any solution for it? and how?
Thank you.
Jheng-Fong
Jheng-Fong, Have submitted update to CRAN, you can download and install from source from my bitbucket account.
This system is improved for the reason that it produces a far more uniformed blood movement into the penis not like the vacuum
motion that can sometimes develop air pockets.
Thanks Yvette for your incredibly irrelevant comment.
Hi everybody.
I manage to make the plot am trying to color my data with a numerical variable. Is it possible to get a color gradient?
Thank you very much
Hi Nicholas,
Thank you for creating such beautiful package. I am quite new to R language, I am working on classifying oceanic rocks, I want to draw the boundaries in the ternary diagram using some conditions and then I want to see where the points fall, would you kindly tell me how to do it using this library? Thank You.
Dear Nicholas,
is there a way to implement function similar geom_encircle from package ‘ggalt’? I see on the top picture of this website you have the green area drawn around data points. I need to do the same thing for my data points. Stat_density_tern isn’t what I need.
Regards,
David
David, sorry for the delay. This should be easy. Can you email me?
nick at ggtern.com
David, the next version coming out has geom_encircle as an approved geometry.
David, geom_encircle is now an approved geometry…
Hi!
is there any way to plot a QAP(F) plot (for plutonic rocks) using ggtern? i.e. a template like the Shepards Classification of Sediments?
Best regards,
Martin
hmmm interesting. Doing the top half, and the bottom half independently is easy. Putting them together is a little harder. I have been thinking about the best way to do piper diagrams, and this problem is a little similar. Let me think about it.
Hi Nicholas,
thank you for your very fast reply!
Best regards,
Martin
Dear Nicholas,
I already made the polygon set for a (Plutonic) QAP diagram, feel free to use it. (I hope its in the right form, I was orientating on your Shepards Classification)
Thanks Martin
Hi!
Your package looks very useful. I noticed, that it’s not yet added to the ggplot-extensions website http://www.ggplot2-exts.org/index.html. Ever thought about adding it? I think that would be a benefit for all gpplot2 users.
Best regards
Thomas
Um, yeah I have been meaning to do that for a while.
Hi Nicholas, Just passing by to recommend another publication using your ggtern R package – loved to play (and struggle a bit) with that!
http://onlinelibrary.wiley.com/doi/10.1002/2017GL072759/full
See Figs 2, S6 and S8
Thanks heaps for developing!
Cheers
Ralph Trancoso
Looks Good!
I have noticed you don’t monetize your page, don’t waste your traffic, you can earn additional bucks every month because you’ve got hi quality content.
If you want to know how to make extra bucks, search for: Mrdalekjd methods for $$$
I have noticed you snuck-under my spam filter you little trickster.
Can you adjust the axis values so that they do not equal 100. For instance x data range 0-30, y range 0-20, z from 0-50? Also how do you list negative values?
Thanks!
Paul, yes, however, ranges need to be valid. The ones you have provided are not. See ?limit_tern, example: ggtern() + limit_tern(1,.4,.4) There is also for exampe, ggtern() + theme_zoom_T(.8), see ?theme_zoom
Dear author!
Can you tell me what is the meaning of “expand=1″ in the structure of stat_interpolate_tern(….., expand=1….).
If I already have the relationship between Value and x,y. How can I insert to your structure?
For instance!
V=c(0, 50, 50, 33.3, 66.6, 16.7, 16.7)
H=c(100, 50, 0, 33.3, 16.7, 66.6, 16.7)
S=c(0, 0, 50, 33.3, 16.7, 16.7, 66.6)
A=c(290.8, 607.3, 503.8, 486.0, 647.6, 356.1, 183.2)
vd=data.frame(V, H, S, A)
ggtern(vd,aes(V,H,S,value=A)) +stat_interpolate_tern(geom=”polygon”,formula=value~x+y,method=lm,n=200,breaks=seq(0,1300,by=100),aes(fill=..level..),expand=1) +geom_point()
While I already know that value=A=27.6+9.11*V+2.68*H!
How can I download it?
Dear Nicholas Hamilton ,
Hello, How I can download it? , It looks so nice and I think we could use it in our analysis.
So would you please help me in download it.
Thank you
Firas
Do you have R installed? This is a package for the R language for statistical computing. My advice, install R, RStudio (IDE), and then you need the required packages (ggplot2, ggtern, etc….). If you are not familiar with ggplot2 syntax, then you may have some work to do, in order to become proficient.
yes I download the r what is the next step plz
Hi,
Many thanks for this package.
This is a very useful tool for presenting the information. In my case, I have made a ternary diagram given a weight of household. I want to change the size/colour of the dots as per their size of the household, but I could not do that. Although I have kept the ‘scale_shape_manual’ in the script, it does not produce the colour accordingly. Please look into the following script.
ggtern(data=ternary_data, aes(General, Muslims, SC/ST)) +
geom_point_swap(aes(fill=Total), size=6, shape=20) +
geom_mask() +
labs(fill=”Households”, colour=”Cylinders”) +
scale_shape_manual(values=c(21,24)) +
scale_color_gradient(low=’green’,high=’red’) +
theme_rgbw() +
theme(legend.position=c(0.0,0.9), legend.justification=c(-0.1,1))
where, General, Muslims, SC/ST are the groups of a population presented in a ternary diagram. ‘Total’ in the second line represent the weight based on which I want to decide the size/colour of the dots in the diagram. For example, ‘Temperature’/’P. Gpa’ is in your following diagram. Could you please suggest me a solution?
http://www.ggtern.com/wp-content/uploads/2013/12/feldspar.png
There are a few things, ‘fill’ and ‘colour’ are two different mappings for those shapes. Also, you need to map ‘size’ to a variable, rather than using a fixed size.
Without seeing your data, perhaps consider the following.
Hi,
Thank you very much for your prompt reply.
I got what I exactly wanted using this script.
Thanks
Dear Nicholas Hamilton,
Is it possible that the error bars of data points can be incorporated into the ternary plot?
Cheers,
Sean
Sean, yes, see
?geom_errorbarX
, there are three geometries (ie geom_errorbarT, geom_errorbarL and geom_errorbarR). There is an example in the help file above.Dear Nicholas,
Thank you for this very nice package. I am using it for my shiny app. But somehow, I have some compatibility issues.
I am currently using ggplot2 + plotly in my shiny app, but once I load ggtern (not attached), or call ggtern using ggtern::ggtern, other dynamic plots using ggplotly do not work.
For example:
library(ggplot2)
library(plotly)
pp <- data.frame(x=c(1,2,3),y=c(4,5,6))
g <- ggplot(pp, aes(x=x,y=y)) + geom_line()
ggplotly(g)
loadNamespace(“ggtern”)
ggplotly(g)
In the above code, before “loadNamespace(“ggtern”), the ggplotly(g) works fine. But after that, it throws an error:
Error in inherits(theme[[element]], .element_tree[[element]]$class) :
‘what’ must be a character vector
Do you know what’s happening here? Thank you very much!
Best,
Junyan
This is still an issue!?
As of R 3.4.0,
NULL
variables can no longer have attributes.From the NEWS:
This means that using
geom_density_tern()
results in lots of errors.To reproduce, run
example(geom_density_tern)
and look at thewarnings()
.At the moment I cannot work with this function at the moment…
This is still an issue!?
As of R 3.4.0,
NULL
variables can no longer have attributes.From the NEWS:
This means that using
geom_density_tern()
results in lots of errors.To reproduce, run
example(geom_density_tern)
and look at thewarnings()
.At the moment I cannot work with this function. Is it planned to solve?
See my response to John Below.
Nicholas, many thanks for a wonderful package. I use it extensively, and it featured prominently in an AAPS talk I gave last spring. I am looking forward to the new version with hexbinning etc.
————————————
I am pretty sure the
“structure(NULL, ..) is now deprecated as you cannot set attributes on NULL.”
message/error is due to a function in the compositions package. At least that is what generates the message for me. That package has not been updated in more than three years. Given that this warning will apparently become an error in R 3.4, this is more than a little concerning.
JS
John,
Excellent, good to hear.
Thansk for letting me know about the structure(NULL,…) error, which was brought to my attention by someone else too. If compositions doesn’t sort it out, do not worry, I can get rid of the package altogether in favour of writing my own versions of the two functions that it is used for (acomp and ilr) in terms of ggtern.
Cheers.
NH
I see you don’t monetize your blog, don’t waste your traffic, you can earn additional
bucks every month because you’ve got hi quality content.
If you want to know how to make extra bucks, search for:
Ercannou’s essential tools best adsense alternative
Is there any possibility to avoid overlapping text when using “geom_text” and have something like an automatic placement? The following code will suppress Label 2 but I would like to have Label 2 plotted without overlap at alternative position. I know how to do it manually, but I have a lot of points and a lot of plots….
df=data.frame(x=c(0.7,0.71),y=c(0.1,0.1),z=c(0.2,0.19) )
base= ggtern(data=df, aes(x,y,z))
A = base + geom_text(data=df, aes(label=1:2,angle=0),check_overlap = T)
hi, Nicholas, i have question: how to change the order of arrows (with axes) in ggtern?, thanks.
Dear Sir,
I am a R program user and read about your R package for “Shepard Sediment classification diagram”. I have data on sediment-grain size and want to make “Shepard Sediment classification diagram” but it is my first time to work on sediment grain size data as I am a fisheries biologist. I need your kind help, how to prepare data to present it via a ternary plot using your packages.
Way at the top, was it intended to be baRycentric?
Hi Nicholas
Ggtern is a amazing package for visualizing allometrical relationships.
I was wondering whether it is possible to calculate the area of either a polygon or a confidence ellipse plotted in ggtern. And whether if it is probable to calculate said area, would it be possible to calculate the percentage or overlap area of two polygons or ellipses plotted on the same graph.
Dear Nicholas, great work on ggtern !
I tried to download the package ggtern using R studio version 3.4.4 from CRAN, but I always get this error:
Hello. This is an amazing package! However, is this working in the new ggplot version?
Thank you!
# Script
library(ggplot2)
library(ggtern)
df = data.frame(x = runif(50),
y = runif(50),
z = runif(50),
Value = runif(50,1,10),
Group = as.factor(round(runif(50,1,2))))
ggtern(data=df,aes(x,y,z,color=Group)) +
theme_rgbw() +
geom_point() + geom_path() +
labs(x=”X”,y=”Y”,z=”Z”,title=”Title”)
error message: Error in f(…, self = self) : unused argument (plot$coordinates)
packageVersion(“ggtern”)
‘2.2.1’
packageVersion(“ggplot2”)
‘3.0.0’
R.Version()
$version.string
[1] “R version 3.5.1 (2018-07-02)”
$nickname
[1] “Feather Spray”
I have noticed you don’t monetize your blog, don’t waste
your traffic, you can earn additional cash every month.
You can use the best adsense alternative for any type of website (they approve all websites), for more
info simply search in gooogle: boorfe’s tips monetize your
website
Hi Nicholas,
Thanks for your package. Unfortunately I can’t install it as I have this error:
> install.packages(‘ggtern’)
Error in readRDS(file) : unknown input format
Error in readRDS(file) : unknown input format
Error in readRDS(file) : unknown input format
Error in readRDS(file) : unknown input format
Installing package into ‘C:/Users/jdeme/OneDrive/Documents/R/win-library/3.5’
(as ‘lib’ is unspecified)
Error in readRDS(file) : unknown input format
Error in readRDS(file) : unknown input format
Error in readRDS(file) : unknown input format
Error in readRDS(file) : unknown input format
Error in readRDS(file) : unknown input format
Error in readRDS(file) : unknown input format
Error in readRDS(file) : unknown input format
Error in readRDS(file) : unknown input format
There is a binary version available but the source version is later:
binary source needs_compilation
ggtern 3.0.0 3.0.0.1 FALSE
installing the source package ‘ggtern’
trying URL ‘https://cran.rstudio.com/src/contrib/ggtern_3.0.0.1.tar.gz’
Content type ‘application/x-gzip’ length 572470 bytes (559 KB)
downloaded 559 KB
* installing *source* package ‘ggtern’ …
** package ‘ggtern’ correctement décompressé et sommes MD5 vérifiées
** R
** data
** demo
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
converting help for package ‘ggtern’
finding HTML links … done
aes html
annotate html
finding level-2 HTML links …
Erreur : format d’entrée inconnu
* removing ‘C:/Users/jdeme/OneDrive/Documents/R/win-library/3.5/ggtern’
In R CMD INSTALL
Warning in install.packages :
installation of package ‘ggtern’ had non-zero exit status
The downloaded source packages are in
‘C:\Users\jdeme\AppData\Local\Temp\Rtmp4MLLfy\downloaded_packages’
Error in readRDS(pfile) : unknown input format
I can’t figure out why the installation can’t process
Thanks for your support
Congratulations on your publication!
Dear Nicholas, thanks a lot for all the greazt work on ggtern. I am trying to study a the highest density points of 3 variables together, and since I have a lot of data (585) I can’t actually put data label on each of them to see which one is each point, I rather prefer checking the highest density data (the ones in the highest density of the ternary plot. I am using this code right now:
plot <- ggtern(data = density1, aes(onshore_r, offshore_r, PV_r))
plot + stat_density_tern(geom=’polygon’,n= 200,aes(fill = ..level..,alpha = abs(..level..))) +
geom_density_tern()+
geom_point() +
theme_rgbw() +
scale_fill_gradient(low = “blue”,high = “red”)
and it works quite well for the visualisation of my data and the density but still not enough for me, I want to choose 5-10 most representetive points. do you know how I can put some labels based on the density intesity?
Thanks a lot.
Hi,
First, I really like your package ! It’s a great job and very useful !!!
I’m using the “R version 3.5.2 (2018-12-20)”
I’ve installed the ggplot2 and ggtern from CRAN source (3.1.0)
The installation is ok but when I try to run the following example I’ve an error message :
—
—
Error in theme_tern_rgbw() :
impossible de trouver la fonction “theme_tern_rgbw”
—
When loading the ggplot2 package I’ve also the following message :
The following objects are masked from ‘package:ggplot2’:
%+%, aes, annotate, calc_element, ggplot, ggplot_build, ggplot_gtable, ggplotGrob, ggsave, layer_data, theme,
theme_bw, theme_classic, theme_dark, theme_gray, theme_light, theme_linedraw, theme_minimal, theme_void
—
Others examples seem to work if them_tern_*** is not called.
Could you help me to see where is the problem,
Thank you,
Olivier
Sorry, error of copy-paste,
This is the code :
—
#Orignal Data as per Question
a <- c(0.1, 0.5,0.5, 0.6, 0.2, 0 , 0 , 0.004166667, 0.45)
b <- c(0.75,0.5,0 , 0.1, 0.2, 0.951612903,0.918103448, 0.7875 , 0.45)
c <- c(0.15,0 ,0.5, 0.3, 0.6, 0.048387097,0.081896552, 0.208333333, 0.10)
d <- c(500,2324.90,2551.44,1244.50, 551.22,-644.20,-377.17,-100, 2493.04)
df <- data.frame(a, b, c, d)
#For labelling each point.
df$id <- 1:nrow(df)
#Build Plot
ggtern(data=df,aes(x=c,y=a,z=b),aes(x,y,z)) +
stat_density2d(geom=”polygon”,
n=400,
aes(fill=..level..,
weight=d,
alpha=abs(..level..)),
binwidth=100) +
geom_density2d(aes(weight=d,color=..level..),
n=400,
binwidth=100) +
geom_point(aes(fill=d),color=”black”,size=5,shape=21) +
geom_text(aes(label=id),size=3) +
scale_fill_gradient(low=”yellow”,high=”red”) +
scale_color_gradient(low=”yellow”,high=”red”) +
theme_tern_rgbw() +
theme(legend.justification=c(0,1), legend.position=c(0,1)) +
guides(fill = guide_colorbar(order=1),
alpha= guide_legend(order=2),
color=”none”) +
labs( title= “Ternary Plot and Filled Contour”,
fill = “Value, V”,alpha=”|V – 0|”)
#Save Plot
#ggsave(“TernFilled.png”)
—
Hey Nicholas, I had some problems with ggtern package. I’m trying to change the orientation of the axes, so for example, the 0 on the axis right now is replaced by 100, and the 100 is replaced by 0. But no matter how hard I tried, I failed.
Hi Nicholas, I want to use your ggtern package in ternary diagrams, but after installed the package I couldn’t load it in to R. I am running R 3.6.0 in Rstudio (version: 1.2.1335) with Window 10. I not an experienced R programmer, hope you can help me! Thank you~# the problem> library(“ggtern”)Loading required package: ggplot2Registered S3 methods overwritten by ‘ggplot2’: method from [.quosures rlang c.quosures rlang print.quosures rlangRegistered S3 methods overwritten by ‘ggtern’: method from +.gg ggplot2 grid.draw.ggplot ggplot2 plot.ggplot ggplot2 print.ggplot ggplot2Error: package or namespace load failed for ‘ggtern’: .onLoad failed in loadNamespace() for ‘ggtern’, details: call: modify_list(vals, list(…, … = NULL)) error: could not find function “modify_list”
Dear Nicholas, I solved the problem! I shut the Antivirus Software down and then it worked, I think maybe the Antivirus Software do not give R the permission to write. Hope this will help others with similar errors, and thanks again to your fantastic package!
I am ecologist and use this package for the Grime`s triangle of plant ecology strategies. Thank you for this package!
Hi Nicholas, thanks for this package, seems really nice! But, I’m having some trouble in loading the package, I receive the following error message: Error: “package or namespace load failed for ‘ggtern’: .onLoad failed in loadNamespace() for ‘ggtern’, details: call: modify_list(vals, list(…, … = NULL)) error: could not find function “modify_list””
I have already updated the R version, reinstalled Rtools, etc… But the problem continues! I found a recent comment from @Victor saying that shutting antivirus down would solve the problem, but that was not the case… Any idea of what’s going on?
Hi there,
I had the same problem, and found that updating my existing R packages did the trick. Hope that’s helpful.
Dear Sir,
I am getting very good awareness about ggtern regarding your explanation
Thankyou
My data is clumping to one side of the ternary plot. Is anyone aware of a way to zoom in on part of the plot? With a regular xy plot you can adjust xy limits but this doesn’t make sense in a ternary plot. I simply want to crop the small part of the plot where my data exist. I’m working in a SVG file format so this is not something I can easily do outside of R. Any ideas? ggtern is a very helpful package btw, much thanks to Nicholas.
Doing some searching I’ve found the useful function tern_limits(). I would still be interested in a pure crop if it can be done but I think I can make this work for my purposes.
Hi Nicholas,
Thank you for your great help and support. I’d love to use this package, but I’m having troubles loading it. This is the error I get:
> library(ggtern)
Error: package or namespace load failed for ‘ggtern’:
.onLoad failed in loadNamespace() for ‘ggtern’, details:
call: modify_list(vals, list(…, … = NULL))
error: could not find function “modify_list”
My R version should be the most updated, and I believe the package is installed correctly. Do you have any idea what the problem would be?
Thank you for your help!
Hi Nicholas,
Great tool!
I have no problem in installing ggtern, although i keep getting “Error: $ operator is invalid for atomic vectors” when running any script. A very simple example:
x <- data.frame(
x1 = c( 0, 0, 1, 0.1, 0.6, 0.2 ),
x2 = c( 0, 1, 0, 0.3, 0.2, 0.8 ),
x3 = c( 1, 0, 0, 0.6, 0.2, 0.0 ))
ggtern(data=x,aes(x2,x1,x3)) + geom_mask() + geom_point(fill=”red”,shape=21,size=4) + theme_bw()
Do you have any solution?
Hi!
I came across your post, as I had the same issue.
apparently, there is a problem with the new ggplot2 version (3.3.0) where ggtern does no longer work.
you need to install an older version of ggplot2 (3.2.1), afterwards it works again.
I just used the same solution. I was trying to update a graph I did in february (which worked), and it was not working until I changed ggplot2 to version 3.2.1
Hopefully the issue gets resolved soon, and we can all use up to date packages?
I love ggtern!
Thank you for this package!
I was wondering if you have plans to make it possible to use ggrepel::geom_text_repel().
Since the era of Charlemagne
Dear All,
I am very interested to this package that I have discovered only recently. I think there are some incompatibilities with the last version because the output of a special template is not really regular. I see there are issues between the last versions. I have also a problem installing devtools(I work under Windows).
Here is whereIi posted my topic: https://stackoverflow.com/questions/67018202/ternary-diagrams-in-r-ggter-3-3-0-vs-older-versions
Is this a problem connected to the compatibility with the new version of ggplot2?
Is there any plan to update ggtern package to fix this issue?