For labelling a plot, I am trying to rotate a character string using text() so that characters are upright and reading down, for example, ... L i k e t h i s . It appears that par crt does not work with text. Does anyone have any other suggestions. Thanks! Yours - Stuart Rosen
Rotating characters in text
8 messages · Stuart Rosen, David Winsemius, Greg Snow +4 more
On Jun 12, 2012, at 9:49 AM, Stuart Rosen wrote:
For labelling a plot, I am trying to rotate a character string using text() so that characters are upright and reading down, for example, ... L i k e t h i s . It appears that par crt does not work with text. Does anyone have any other suggestions.
Just print the letters separately. Something like this untested use of
`mapply`:
mapply(text, labels=strsplit(txvec, ""),
x=1, # or some other appropriate number, should get recycled.
y=seq(start, end, length=nchar(txvec) )
David Winsemius, MD West Hartford, CT
If you insert `\n` between each letter, then it should do what you want with a single call to text or mtext. To expand on David's example: plot(1:10) text(5,5, paste( strsplit(txvec, ''), collapse='\n') ) On Tue, Jun 12, 2012 at 10:16 AM, David Winsemius
<dwinsemius at comcast.net> wrote:
On Jun 12, 2012, at 9:49 AM, Stuart Rosen wrote:
For labelling a plot, I am trying to rotate a character string using text() so that characters are upright and reading down, for example, ... L i k e t h i s . It appears that par crt does not work with text. Does anyone have any other suggestions.
Just print the letters separately. Something like this untested use of `mapply`: mapply(text, labels=strsplit(txvec, ""), ? ? ? ?x=1, ?# or some other appropriate number, should get recycled. ? ? ? ?y=seq(start, end, length=nchar(txvec) ) -- David Winsemius, MD West Hartford, CT
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Gregory (Greg) L. Snow Ph.D. 538280 at gmail.com
Try this, rotate = function(x) paste(strsplit(x,"")[[1]],collapse="\n") t <- "this is a text" plot.new() text(1/2,1/2,t) par(lheight=0.8) text(1/2,1/2,rotate(t)) HTH, b.
On 13 June 2012 01:49, Stuart Rosen <s.rosen at ucl.ac.uk> wrote:
For labelling a plot, I am trying to rotate a character string using text() so that characters are upright and reading down, for example, ... L i k e t h i s . It appears that par crt does not work with text. Does anyone have any other suggestions. Thanks! Yours - Stuart Rosen
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Hello,
(You forgot to unlist() the result of strsplit.)
Another way, saving some space between characters is to use strheight().
rotate90 <- function(x, y, label){
label <- unlist(strsplit(label, ''))
y <- y - (seq_along(label) - 1)*strheight(label)
list(x=x, y=y, label=label)
}
txt <- rotate90(5, 5, "Test rotate90")
plot(1:10)
text(txt$x, txt$y, txt$label)
Rui Barradas
Em 12-06-2012 21:02, Greg Snow escreveu:
If you insert `\n` between each letter, then it should do what you want with a single call to text or mtext. To expand on David's example: plot(1:10) text(5,5, paste( strsplit(txvec, ''), collapse='\n') ) On Tue, Jun 12, 2012 at 10:16 AM, David Winsemius <dwinsemius at comcast.net> wrote:
On Jun 12, 2012, at 9:49 AM, Stuart Rosen wrote:
For labelling a plot, I am trying to rotate a character string using text() so that characters are upright and reading down, for example, ... L i k e t h i s . It appears that par crt does not work with text. Does anyone have any other suggestions.
Just print the letters separately. Something like this untested use of
`mapply`:
mapply(text, labels=strsplit(txvec, ""),
x=1, # or some other appropriate number, should get recycled.
y=seq(start, end, length=nchar(txvec) )
--
David Winsemius, MD
West Hartford, CT
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
On Jun 12, 2012, at 4:02 PM, Greg Snow wrote:
If you insert `\n` between each letter, then it should do what you want with a single call to text or mtext. To expand on David's example: plot(1:10) text(5,5, paste( strsplit(txvec, ''), collapse='\n') )
In fact it could be made even easier:
(Copied from you original.)
txvec <- c("L
i
k
e
t
h
i
s
.")
plot(1,1)
text(0.8, 1, labels=txvec)
--
David.
On Tue, Jun 12, 2012 at 10:16 AM, David Winsemius <dwinsemius at comcast.net> wrote:
On Jun 12, 2012, at 9:49 AM, Stuart Rosen wrote:
For labelling a plot, I am trying to rotate a character string using text() so that characters are upright and reading down, for example, ... L i k e t h i s . It appears that par crt does not work with text. Does anyone have any other suggestions.
Just print the letters separately. Something like this untested use
of
`mapply`:
mapply(text, labels=strsplit(txvec, ""),
x=1, # or some other appropriate number, should get recycled.
y=seq(start, end, length=nchar(txvec) )
--
David Winsemius, MD
West Hartford, CT
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
-- Gregory (Greg) L. Snow Ph.D. 538280 at gmail.com
David Winsemius, MD West Hartford, CT
On 06/12/2012 11:49 PM, Stuart Rosen wrote:
For labelling a plot, I am trying to rotate a character string using text() so that characters are upright and reading down, for example, ... L i k e t h i s . It appears that par crt does not work with text. Does anyone have any other suggestions. Thanks!
Hi Stuart, Is this what you want? plot(1:5) text(3,3,"L\ni\nk\ne\n\nt\nh\ni\ns\n") Jim
Or for the y label and using gsub:
plot(1:5, ylab="")
text(.35,3, gsub("(.)", "\\1\n", "Like this"), xpd=TRUE)
Sticking it in ylab= does not work.
----------------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352
-----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- project.org] On Behalf Of Jim Lemon Sent: Wednesday, June 13, 2012 5:02 AM To: s.rosen at ucl.ac.uk Cc: r-help at r-project.org Subject: Re: [R] Rotating characters in text On 06/12/2012 11:49 PM, Stuart Rosen wrote:
For labelling a plot, I am trying to rotate a character string using text() so that characters are upright and reading down, for example,
...
L i k e t h i s . It appears that par crt does not work with text. Does anyone have any other suggestions. Thanks!
Hi Stuart, Is this what you want? plot(1:5) text(3,3,"L\ni\nk\ne\n\nt\nh\ni\ns\n") Jim
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code.