Help is on the way [Off Topic]
Hi ElMaestro,
Hope you enjoy it.
The problem with your code is that
A workaround:
With the additional argument
❝ hot greetings from Ahmedabad.
Hope you enjoy it.
The problem with your code is that
rect()
does not – and can not – ‘know’ how wide text()
will be.A workaround:
foo2 <- function(name, h, w, values, loc, cex, lgd) {
pdf(name, height = 4, width = 3)
barplot(values, las = 1)
legend(loc, legend = lgd,
cex = cex, # trial & error
x.intersp = 0, # otherwise, we have a left margin
trace = TRUE) # shows user coordinates in the console
dev.off()
}
name <- "foopdf2.pdf"
foo2(name = name, h = 4, w = 3,
values = c(8, 2, 3, 3, 1, 2, 3, 1, 9),
loc = "center", cex = 0.85,
lgd = c("Text is ok.", "Text is also ok."))
system2("open", args = name, wait = TRUE)
With the additional argument
plot = FALSE
you could assign all what is needed to a variable:w, h
positive numbers giving width and height of the legend’s box.
left, top
x and y coordinates of upper left corner of the box.x, y
numeric vectors of lengthlength(legend)
, giving the x and y coordinates of the legend's text(s).
rect
a list with componentstext
a list with componentslegend()
directly (eventually with x, y
coordinates) is much simpler. See the examples at the end of the man page of legend
.—
Dif-tor heh smusma 🖖🏼 Довге життя Україна!
Helmut Schütz
The quality of responses received is directly proportional to the quality of the question asked. 🚮
Science Quotes
Dif-tor heh smusma 🖖🏼 Довге життя Україна!
Helmut Schütz
The quality of responses received is directly proportional to the quality of the question asked. 🚮
Science Quotes
Complete thread:
- text function in R, how to get an idea of width? ElMaestro 2022-04-24 19:09 [Off Topic]
- Help is on the wayHelmut 2022-04-24 22:24
- The width of text is important, not the rectangle ElMaestro 2022-04-25 04:20
- I suggest strwidth() Helmut 2022-04-25 09:26
- The width of text is important, not the rectangle ElMaestro 2022-04-25 04:20
- Help is on the wayHelmut 2022-04-24 22:24