0
library(grid)
library(Gmisc)
grid.newpage()
gp <- gpar(fill = "lightgrey")
(total <- boxGrob("some text doesnt fit", 
                      x=0.55, y=.6, box_gp = gp,just = "center",width = 0.1,height = 0.1))

using the above code I want to reduce the text size to fit inside the box. is there an easy way with cex or auto sizing call? Any help would be appreciated.

enter image description here

e.matt
  • 836
  • 1
  • 5
  • 12

1 Answers1

0

There is no autosizing call. What you need to specify is the txt_gp argument, e.g.:

grid.newpage()
gp <- gpar(fill = "lightgrey")
(total <- boxGrob("some text doesnt fit", 
                  x=0.55, y=.6, 
                  box_gp = gp,
                  just = "center",
                  width = 0.1,
                  height = 0.1,
                  txt_gp = gpar(fontsize = 5)))

You could experiment with calculating the width and adjusting it accordingly. Currently the width is calculated using:

txt_padding <- unit(4, "mm")
width <- grobWidth(txt) + txt_padding + txt_padding

Just experiment with different sizes and see if it is within your limits. The grobWidth is part of the grid package.

Max Gordon
  • 5,367
  • 2
  • 44
  • 70