rplotrix

Does anybody know a function to avoid point labels to overlap in R?


Ternary diagram Hello. Does anybody know how to use thigmophobe.labels from PLOTRIX? or any other function that voids the point labels to overlap? I am trying to make a ternary diagram with sediment data, but I got this problem and I have no idea how to solve it. Some point labels are overlapping. Maybe it's simple, but I a new R user...

That's an example of the code.

library ('rysgran')
data (camargo2001)

class.percent (camargo2001, mode="total")
percent <- class.percent(camargo2001, mode="total")
x<-percent[2:4]
rysgran.ternary(x, method = "pejrup", lang = "e", main="",
                show.labels=FALSE, label.points=TRUE, axis.labels = NULL, show.names = TRUE,
                cex.labels= 1, cex.points=0.9, show.legend=FALSE,
                cex.axis=1, cex.names = 0.8, col.names = "blue", col = "blue",
                col.labels= "black", col.axis= "black", col.lines= "black",
                pch = 16, lty.grid = 10, pos=3)

Solution

  • This will be difficult because the points are so clustered in the lower left corner. Also helper functions such as thigamaphobe.labels in plotrix (and the other functions mentioned on the manual page for the function) need to know the coordinates of the point, but rysgran.ternary does not return that information. Some of the other ternary plot functions do or provide a function to convert the 3d coordinates to 2d plot coordinates.

    Given that, you may be able to get by with some of the following approaches:

    1. If you are plotting to a print device, make the plot bigger so that the overlaps are not as severe. When I recreate your plot and drag the window larger, many of the overlaps disappear.

    2. Change cex.labels= to something smaller, e.g. .8. That will make the labels smaller.

    3. Reposition the labels with pos=c(3, 2, 1, 1, 3, 3, 3, 3, 3, 3, 1, 3, 3, 3). That tells R where to plot the label relative to the point, 1-below, 2-left, 3-above, 4-right. Currently you are plotting all labels using 3, above the point.

    4. More work, but more control. Do not plot the labels automatically. Generate the plot and then use pt <- locator() and click on the points on the graph to get their plot coordinates. Use this information with points() to plot the labels exactly where you want them. Save the coordinates so whenever you regenerate the plot, you have the coordinates already computed.