Home > Net >  How to cut a long text character in a plot in R
How to cut a long text character in a plot in R

Time:12-08

I have a long text that I want to plot to an image in R, the image size 300 x 200 pixel. The actual text will vary.

Example Image

enter image description here

Example Code

library(raster) 
myJPG <- stack("images/1.jpg")  # Image with 300 x 200 pixel size
plotRGB(myJPG)  

vt <- rep(1:100)
vt <- paste(vt, collapse = ' ')


text(x = 150, y = 70,
     labels = vt,
     adj = c(0.5,0.5),
     cex = 1,
     col = "white")

Example Result.

result

What I want to ask How to cut the text in labels automatically, and adjust it so all the text can be shown in the image?

CodePudding user response:

You can insert \n into your character vector vt to break a line. One way to do this automatically enter image description here

  • Related