0

I am using a triangle to mark an event on a timeline in R, and I've given the coordinates to the specific position on the line where the event occurs in days. In the points( function, I have supplied pch=25 to create the "filled triangle" shape. However, the positioning of the character is based on the center of the triangle. Is it possible to use an argument like "pos" (i.e. pos=3) so that the triangle is positioned immediately above the line and points to to X coordinate of interest?

Example:

plot.new()
segments(0, 0.5, 1, 0.5)
points(0.5, 0.5, pch=25)

have

enter image description here

want

enter image description here

AdamO
  • 4,283
  • 1
  • 27
  • 39
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Nov 17 '22 at 20:36
  • @MrFlick It seemed straightforward to me, but anyway I added the code/have/want. – AdamO Nov 17 '22 at 21:23
  • I don't believe such a feature exists for plotting characters. I don't think they are aware of their own size. You could just bump the position a bit `points(0.5, 0.52, pch=25)` or plot your own triangles with `polygon` and have complete control over vertex positioning. – MrFlick Nov 17 '22 at 21:27

2 Answers2

0

I dont think there is an inherent function for this (i.e. pos-like function) but in the past, I have added a manual adjustment:

plot.new()

adj <- 0.015

segments(0, 0.5, 1, 0.5)
points(0.5, 0.5 + adj, pch=25)

enter image description here

So with multiple points:

points(seq(0.1, 0.9, 0.1), rep(0.5, 9) + adj, pch = 25)

enter image description here

jpsmith
  • 11,023
  • 5
  • 15
  • 36
0

Since R's interpreter supports a wide variety of encodings, and since the pch is just the text input, you can just paste the down triangle into the text editor and calculate:

strheight('▽') -> l

and change the last line to points(0.5, 0.5 + l/2, pch=25) to get the desired

enter image description here

> strheight('▽')
[1] 0.1022132
AdamO
  • 4,283
  • 1
  • 27
  • 39