Reputation: 27430
I have a ternary plot that I'm generating like this:
library(vcd)
ternaryplot(abs(replicate(3, rnorm(50))), grid=FALSE)
I don't like the built-in grid so I disabled it, but I want to draw some lines of my own: specifically I want to draw a line from each point of my triangle to the midpoint of the opposite face (i.e. three lines bisecting my triangle and crossing at the center) and I can't quite figure out how to do this. I tried abline()
but nothing seems to happen when I do.
How can I draw lines on this plot?
Upvotes: 4
Views: 1698
Reputation: 10526
In the latest version, ggtern 2.0.1, there is now a couple of new geometries to make isoproportion lines, here is an example:
#Demonstrate the isoprop geometries
df = data.frame(x=1,y=1,z=1)
ggtern(data=df,aes(x,y,z)) + geom_point() +
geom_Tisoprop(value=seq(0,1,by=0.25),colour='darkred') +
geom_Lisoprop(value=c(.5),colour='darkgreen') +
geom_Risoprop(value=c(.5),colour='darkblue') +
theme_minimal()
Upvotes: 1
Reputation: 10526
Using the ggtern package which I have recently published on CRAN, the following can be achieved:
Which can be produced with the following code:
library(ggtern)
DATA <- data.frame(x = c(1,0,0),
y = c(0,1,0),
z = c(0,0,1),
xend = c(0,.5,.5),
yend = c(.5,0,.5),
zend = c(.5,.5,0),
Series = c("yz","xz","xy"))
ggtern(data=DATA,aes(x,y,z,xend=xend,yend=yend,zend=zend)) +
geom_segment(aes(color=Series),size=1) +
scale_color_manual(values=c("darkgreen","darkblue","darkred")) +
theme_bw() + theme_nogrid() +
theme(legend.position=c(0,1),legend.justification=c(0,1)) +
labs(title = "Sample Midpoint Segments")
Upvotes: 5
Reputation: 89097
Try this. Most of it I gathered from reading the code for ternaryplot
:
library(vcd)
ternaryplot(abs(replicate(3, rnorm(50))), grid=FALSE)
top <- sqrt(3)/2
xlim <- c(-0.03, 1.03)
ylim <- c(-1, top)
pushViewport(viewport(width = unit(1, "snpc")))
pushViewport(viewport(width = 0.8, height = 0.8, xscale = xlim,
yscale = ylim, name = "plot"))
grid.lines(c(0.75, 0.00), c(0.5 * top, 0))
grid.lines(c(0.25, 1.00), c(0.5 * top, 0))
grid.lines(c(0.50, 0.50), c(1.0 * top, 0))
upViewport(2)
Upvotes: 6