Reputation: 117
Is there any convenient way to get vertical CJK text onto an R plot? Both as labels for points/polygons, and just as part of a block of arbitrary text placed on the plot.
The one potential method I've found so far is to use the ragg
package to pass something like the vrt2
OpenType feature to a font so that it uses one of those glyph sets meant for writing vertical text in a horizontal environment, and then rotating it to be correct. Is there an easier way to do it than that?
Upvotes: 2
Views: 44
Reputation: 44788
Simply putting newlines between the characters might be enough. For example,
plot(1,1)
text(1,1, adj = -1, labels="日\n本", family = "Arial Unicode MS")
Doing a block of text is more tedious: I think each line will need to be drawn separately. For example,
plot(1,1, type="n")
text(1,1.2, adj = c(-1,1), labels="古\n池\nや", family = "Arial Unicode MS")
text(1,1.2, adj = c(0,1), labels="蛙\n飛\nび\n込\nむ", family = "Arial Unicode MS")
text(1,1.2, adj = c(1,1), labels="水\nの\n音", family = "Arial Unicode MS")
produces this:
Edited to add: If the character spacing is unacceptable, you can use the par("lheight")
parameter to adjust it. For example,
plot(1,1, type="n")
par(lheight = 0.8)
text(1,1.2, adj = c(-1,1), labels="古\n池\nや", family = "Arial Unicode MS")
text(1,1.2, adj = c(0,1), labels="蛙\n飛\nび\n込\nむ", family = "Arial Unicode MS")
text(1,1.2, adj = c(1,1), labels="水\nの\n音", family = "Arial Unicode MS")
which gives
It's fairly easy to automate the insertion of newlines, but I'll leave that to you. What would be hard would be to have variable spacing, e.g to insert small spaces or parentheses.
Upvotes: 0