r - Spiral Wrapped Text -


i saw in latex people wrapping text spiral seen below. replicate in r.

enter image description here

i though plotrix's arctext given enough text seems make circle seen in plot (left) below. can make aspiral line seen in plot (right) can not merge text , spiral.

enter image description here

code

txt <- paste(rep("bendy spaghetti", 10), collapse=" ") txt2 <- paste(rep("bendy spaghetti", 20), collapse=" ")  par(mfrow=c(1, 2), mar=rep(.3, 4)+c(0, 0, 1, 0))  library(plotrix) plot.new() plot.window(xlim = c(1, 5), ylim = c(2, 4), asp = 1) arctext(txt, center = c(3, 3), radius = 1.7,    start = 4 * pi / 3, cex = .75, clockwise = false) title(main = "arc text (plotrix)")  theta <- seq(0, 30 * 2 * pi, = 2 * pi/72) x <- cos(theta) y <- sin(theta) r <- theta/max(theta) plot.new() plot.window(xlim = c(-1, 1), ylim = c(-1, 1), asp = 1) lines(x * r, y * r) title(main = "a spiral") 

ideally, solution work on n length text, txt , txt2 above both make wrapping spiral not same size (txt2 double length of txt).

approaches grid/ggplot2 , base grapgics welcomed.

not perfect

txt <- paste(rep("bendy spaghetti", 10), collapse=" ") txt2 <- paste(rep("bendy spaghetti", 20), collapse=" ") tt <- strsplit(txt, '')[[1]]  xx <- 5 par(mfrow = c(1,2), mar = c(0,0,0,0)) plot(-xx:xx, -xx:xx, type = 'n', axes = false, ann = false)  ## option 1 r <- rev(seq(0, xx, length.out = length(tt))) x <- sqrt(r) * cos(2 * pi * r) y <- sqrt(r) * sin(2 * pi * r) text(x, y, tt)  ## option 2 plot(-xx:xx, -xx:xx, type = 'n', axes = false, ann = false) srt <- atan2(y, x) * 180 / pi (ii in seq_along(tt))   text(x[ii], y[ii], tt[ii], srt = srt[ii] - 90) 

enter image description here

obviously, distance between letters shrinks closer center, can improved.

also don't see how can around calling text each new value of srt using approach since srt isn't formal argument meaning couldn't vectorize(text.default, vectorize.args = 'srt'), isn't slow example data.

additionally, make data frame , plug ggplot.

dd <- data.frame(x, y, srt = srt - 90, tt) library('ggplot2') ggplot(dd, aes(x, y)) + geom_text(label = dd$tt, size = 5) ggplot(dd, aes(x, y)) + geom_text(label = dd$tt, size = 5, angle = dd$srt) 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -