Skip to content

Commit 780bdeb

Browse files
Initial Configuration
0 parents  commit 780bdeb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+2212
-0
lines changed

.Rbuildignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
^.*\.Rproj$
2+
^\.Rproj\.user$

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.Rproj.user
2+
.Rhistory
3+
.RData

DESCRIPTION

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
Package: ggtern
2+
Type: Package
3+
Title: An extension to ggplot, to create ternary plots
4+
Version: 1.0
5+
Date: 2013-11-15
6+
Author: Nicholas Hamilton
7+
Maintainer: Nicholas Hamilton <[email protected]>
8+
Description: More about what it does (maybe more than one line)
9+
License: GPL-2
10+
Depends:
11+
ggplot2(>= 0.9.3.1),
12+
proto,
13+
grid,
14+
scales,
15+
plyr,
16+
gtable
17+
Collate:
18+
'element_ternary.R'
19+
'utilities.R'
20+
'theme.R'
21+
'transformTernToCart.R'
22+
'labs.R'
23+
'aes.R'
24+
'scales.R'
25+
'geom_point_tern.R'
26+
'geom_point_tern_new.R'
27+
'geom_text_tern.R'
28+
'geom_path_tern.R'
29+
'geom_polygon_tern.R'
30+
'geom_segment_tern.R'
31+
'ternborder.R'
32+
'ternbackground.R'
33+
'ternlabels.R'
34+
'ternfixedcoords.R'
35+
'ternarrows.R'
36+
'terngridlines.R'
37+
'ternticks.R'
38+
'ggtern.R'
39+
'plot-build.R'
40+
'panel.R'
41+
'chull_tern.R'
42+
'onLoad.R'
43+
'tern-render.R'

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
exportPattern("^[[:alpha:]]+")

R/aes.R

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
3+
#' Modified Aesthetic Mappings
4+
#'
5+
#' An extension to the base aes functin from ggplot2, this is modified to handle a default z mapping for application in ternary phase diagrams.
6+
#' Does not alter the standard behaviour.
7+
#' @param x x value
8+
#' @param y y value
9+
#' @param z z value
10+
#' @seealso Parent \code{\link[ggplot2]{aes}} function.
11+
aes <- function(x,y,z=NULL,...) {
12+
aes <- structure(as.list(match.call()[-1]), class="uneval")
13+
ggplot2:::rename_aes(aes)
14+
}
15+
16+
.aes_hack <- function(){
17+
# Look up the scale that should be used for a given aesthetic
18+
#aes_to_scale <- function(var) {
19+
# var[var %in% c("x", "xmin", "xmax", "xend", "xintercept")] <- "x"
20+
# var[var %in% c("y", "ymin", "ymax", "yend", "yintercept")] <- "y"
21+
# var[var %in% c("T", "Tmin", "Tmax", "Tend", "Tintercept")] <- "T"
22+
# var[var %in% c("L", "Lmin", "Lmax", "Lend", "Lintercept")] <- "L"
23+
# var[var %in% c("R", "Rmin", "Rmax", "Rend", "Rintercept")] <- "R"
24+
# var
25+
#}
26+
#unlockBinding("aes_to_scale", asNamespace("ggplot2"))
27+
# assign("aes_to_scale", aes_to_scale, asNamespace("ggplot2"))
28+
#lockBinding("aes_to_scale", asNamespace("ggplot2"))
29+
30+
# Figure out if an aesthetic is a position aesthetic or not
31+
#is_position_aes <- function(vars) {
32+
# aes_to_scale(vars) %in% c("x", "y","T","L","R")
33+
#}
34+
#unlockBinding("is_position_aes", asNamespace("ggplot2"))
35+
# assign("is_position_aes", is_position_aes, asNamespace("ggplot2"))
36+
#lockBinding("is_position_aes", asNamespace("ggplot2"))
37+
38+
39+
.all_aesthetics <- ggplot2:::.all_aesthetics
40+
.all_aesthetics <- c(.all_aesthetics,"T","L","R","zend")
41+
#PUSH BACK.
42+
unlockBinding(".all_aesthetics", asNamespace("ggplot2"))
43+
assign(".all_aesthetics", .all_aesthetics, asNamespace("ggplot2"))
44+
lockBinding(".all_aesthetics", asNamespace("ggplot2"))
45+
}

R/chull_tern.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
chull_tern <- function(T,L,R,data=data.frame(T=T,L=L,R=R)){chull(transformTernToCart(data=data))}

R/element_ternary.R

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
element_ternary <- function(showarrows =TRUE,
2+
padding =0.15,
3+
arrowsep =0.10,
4+
arrowstart =0.25,
5+
arrowfinish=0.75,
6+
ticklength.major =0.020,
7+
ticklength.minor =0.010){
8+
structure(
9+
list(padding=padding,arrowsep=arrowsep,showarrows=showarrows,arrowstart=arrowstart,arrowfinish=arrowfinish,
10+
ticklength.major=ticklength.major,ticklength.minor=ticklength.minor),
11+
class = c("element_ternary")
12+
)
13+
}

R/geom_path_tern.R

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#----------------------------------------
2+
#PROTO FOR GEOM POINT TERN
3+
#----------------------------------------
4+
geom_path_tern <- function (mapping = NULL, data = NULL, stat = "identity", position = "identity", na.rm = FALSE, ...) {
5+
GeomPathTern$new(mapping = mapping, data = data, stat = stat, position = position, na.rm = na.rm, ...)
6+
}
7+
GeomPathTern <- proto(ggplot2:::Geom,{
8+
objname <- "path_tern"
9+
draw_groups <- function(. ,...){ .$draw(...) }
10+
draw <- function(., data, scales, coordinates, arrow = NULL, lineend = "butt", linejoin = "round", linemitre = 1, ..., na.rm = FALSE) {
11+
data <- remove_missing(data,na.rm,c("x","y","z"),name = "geom_path_tern")
12+
if (empty(data)) return(zeroGrob())
13+
data[,c("x","y")] <- transformTernToCart(data=data[,c("x","y","z")])
14+
ggplot2:::GeomPath$draw(.=., data=data, scales=scales, coordinates=coordinates,arrow = arrow, lineend = lineend, linejoin = linejoin, linemitre = linemitre, ..., na.rm = na.rm)
15+
}
16+
draw_legend <- function(., data, ...) {
17+
ggplot2:::GeomPath$draw_legend(.,data,...)
18+
}
19+
default_stat <- function(.) StatIdentity
20+
required_aes <- c("x","y","z")
21+
default_aes <- function(.) aes(colour="black", size=0.5, linetype=1, alpha = NA,fill=NA)
22+
guide_geom <- function(.) "path"
23+
})
24+
25+

R/geom_point_tern.R

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#----------------------------------------
2+
#PROTO FOR GEOM POINT TERN
3+
#----------------------------------------
4+
geom_point_tern <- function (mapping = NULL, data = NULL, stat = "identity", position = "identity", na.rm = FALSE, ...){
5+
GeomPointTern$new(mapping = mapping, data = data, stat = stat, position = position, na.rm = na.rm, ...)
6+
}
7+
GeomPointTern <- proto(ggplot2:::Geom,{
8+
objname <- "point_tern"
9+
draw_groups <- function(. ,...){.$draw(...)}
10+
draw <- function(.,data, scales, coordinates, ... ,na.rm = FALSE) {
11+
data <- remove_missing(data,na.rm,c("x","y","z"),name = "geom_point_tern")
12+
if (empty(data)) return(zeroGrob())
13+
data[,c("x","y")] <- transformTernToCart(data=data[,c("x","y","z")])
14+
ggplot2:::GeomPoint$draw(.=.,data=data,scales=scales,coordinates=coordinates,...,na.rm=na.rm)
15+
}
16+
draw_legend <- function(., data, ...) {
17+
ggplot2:::GeomPoint$draw_legend(.=.,data=data,...)
18+
}
19+
default_stat <- function(.) StatIdentity
20+
required_aes <- c("x","y","z")
21+
default_aes <- function(.) aes(shape=16,colour="black",size=2,fill = NA,alpha = NA)
22+
})

R/geom_point_tern_new.R

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#----------------------------------------
2+
#PROTO FOR GEOM POINT TERN
3+
#----------------------------------------
4+
geom_point_tern_new <- function (mapping = NULL, data = NULL, stat = "identity", position = "identity", na.rm = FALSE, ...){
5+
GeomPointTernNew$new(mapping = mapping, data = data, stat = stat, position = position, na.rm = na.rm, ...)
6+
}
7+
GeomPointTernNew <- proto(ggplot2:::Geom,{
8+
objname <- "point_tern"
9+
draw_groups <- function(. ,...){.$draw(...)}
10+
draw <- function(.,data, scales, coordinates, ... ,na.rm = FALSE) {
11+
data <- remove_missing(data,na.rm,c("T","L","R"),name = "geom_point_tern")
12+
if (empty(data)) return(zeroGrob())
13+
data[,c("x","y")] <- transformTernToCart(data=data[,c("T","L","R")])
14+
ggplot2:::GeomPoint$draw(.=.,data=data,scales=scales,coordinates=coordinates,...,na.rm=na.rm)
15+
}
16+
draw_legend <- function(., data, ...) {
17+
ggplot2:::GeomPoint$draw_legend(.=.,data=data,...)
18+
}
19+
default_stat <- function(.) StatIdentity
20+
required_aes <- c("T","L","R")
21+
default_aes <- function(.) aes(shape=16,colour="black",size=2,fill = NA,alpha = NA)
22+
})

0 commit comments

Comments
 (0)