Trajectory tree

I am looking to do something similar to this in R. Could this be done with ggplot or some other package?

Trajectory tree

Found in the following blog:

http://intelligenttradingtech.blogspot.com/2011/07/pattern-recognition-forward-boxplot.html

+3
source share
2 answers

Here's how to plot using ggplot2.

enter image description here

I built the data manually, indicating the coordinates of each start and end position of the line. Obviously, an improvement would be to automate this using an algorithm. Since this was not a question, I did not try to solve it.

Create data:

arrowdata <- c(
  0, 0, 1, 0,
  1, 1, 2, 1,
  1, -1, 2, -1,
  2, 1.5, 3, 1.5,
  2, 0.5, 3, 0.5
)

linesdata <- c(
  1, 0, 1, 1,
  1, 0, 1, -1,
  2, 1, 2, 1.5,
  2, 1, 2, 0.5
)

labeldata <- data.frame(
  x = c(0.5, 1.5, 2.5),
  y = c(0, 1, 1.5),
  labels=c("Label 1", "Label2", "Label 3")
)

adat <- as.data.frame(matrix(arrowdata, ncol=4, byrow=TRUE))
ldat <- as.data.frame(matrix(linesdata, ncol=4, byrow=TRUE))

Download the packages ggplot2and gridthen write:

library(ggplot2)
library(grid) # For arrow() function
ggplot() + 
  geom_segment(
    data=adat, 
    aes(x=V1, y=V2, xend=V3, yend=V4),
    arrow=arrow(length = unit(0.05, "npc"), type="closed"),
    col="blue"
  ) +
  geom_segment(
    data=ldat, 
    aes(x=V1, y=V2, xend=V3, yend=V4),
    col="blue"
  ) +
  geom_text(data=labeldata, aes(x, y, label=labels), 
    size=8, vjust=-0.2, col="blue"
  ) +
  theme_bw() +
  opts(
    axis.text.x=theme_blank(),
    axis.text.y=theme_blank(),
    axis.ticks=theme_blank(),
    axis.title.x=theme_blank(),
    axis.title.y=theme_blank(),
    panel.grid.major=theme_blank(),
    panel.border=theme_blank()
  ) +
coord_cartesian(ylim=c(-1.5, 2)) # Create some additional space for labels
+3
source

- http://addictedtor.free.fr/graphiques/. . , plot graphics::arrow, . ,

arrows(0,1,0,0) 
lines(c(1,1),c(-.5,.5)) 
arrows(1,2,.5,.5) 

.. , ?

+1

All Articles